index-tanked 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,7 +13,8 @@ module IndexTanked
13
13
  end
14
14
 
15
15
  def add_fields_to_query(query, options={})
16
- [super, "model:#{@model.name}"].compact.join(" ")
16
+ return nil if super.nil?
17
+ [super, "model:#{@model.name}"].compact.join(" ").strip
17
18
  end
18
19
 
19
20
  def doc_id
@@ -17,7 +17,7 @@ module IndexTanked
17
17
  find_in_batches(options) do |instances|
18
18
  documents = instances.map { |instance| instance.index_tanked.document_for_batch_addition }
19
19
  count += documents.size
20
- index_tanked.retry_on_error do
20
+ index_tanked.retry_on_error(:times => 5, :delay_multiplier => 2) do
21
21
  index_tanked.index.batch_insert(documents)
22
22
  end
23
23
  end
@@ -2,7 +2,7 @@ module IndexTanked
2
2
  module ActiveRecordDefaults
3
3
  class SearchResult < SearchResult
4
4
 
5
- attr_reader :model
5
+ attr_reader :model, :missing_ids
6
6
 
7
7
  def initialize(query, index, model, options={})
8
8
  super(query, index, options)
@@ -14,7 +14,17 @@ module IndexTanked
14
14
  end
15
15
 
16
16
  def records(options={})
17
- @model.find(ids, options)
17
+ base = @model
18
+ base = base.scoped(:conditions => {:id => ids})
19
+ records_found = base.all(options)
20
+ @missing_ids = ids - records_found.map(&:id)
21
+ begin
22
+ if Configuration.missing_activerecord_ids_handler
23
+ Configuration.missing_activerecord_ids_handler.call(@model, @missing_ids)
24
+ end
25
+ ensure
26
+ return records_found
27
+ end
18
28
  end
19
29
 
20
30
  def paginate(options={})
@@ -51,7 +51,8 @@ module IndexTanked
51
51
  end
52
52
 
53
53
  def add_fields_to_query(query, options={})
54
- [query, options[:fields] && options[:fields].to_a.join(":")].compact.join(" ")
54
+ return nil if query.blank? && options[:fields].blank?
55
+ [query, options[:fields] && options[:fields].to_a.join(":")].compact.join(" ").strip
55
56
  end
56
57
 
57
58
  end
@@ -3,7 +3,8 @@ module IndexTanked
3
3
 
4
4
  class << self
5
5
  attr_accessor :url, :index, :search_availability, :index_availability,
6
- :add_to_index_fallback, :delete_from_index_fallback, :timeout
6
+ :add_to_index_fallback, :delete_from_index_fallback, :timeout,
7
+ :missing_activerecord_ids_handler
7
8
 
8
9
  def search_available?
9
10
  if search_availability.is_a? Proc
@@ -47,6 +47,7 @@ module IndexTanked
47
47
  begin
48
48
  raise SearchingDisabledError, "index tank search is disabled in configuration" unless IndexTanked::Configuration.search_available?
49
49
  raise IndexTanked::SearchError, "No or invalid index has been provided" unless @index.is_a? IndexTank::Index
50
+ raise IndexTanked::SearchError, "No query provided" if @query.nil?
50
51
  @raw_result ||= @index.search(@query, @options.merge(:start => pager.offset, :len => pager.per_page))
51
52
  rescue StandardError => e
52
53
  raise if e.is_a? IndexTankedError
@@ -1,3 +1,3 @@
1
1
  module IndexTanked
2
- GEM_VERSION = '0.1.7'
2
+ GEM_VERSION = '0.1.8'
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: index-tanked
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 7
10
- version: 0.1.7
9
+ - 8
10
+ version: 0.1.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Adam Kittelson