Class: IndexTanked::ActiveRecordDefaults::SearchResult
- Inherits:
-
SearchResult
- Object
- SearchResult
- IndexTanked::ActiveRecordDefaults::SearchResult
- Defined in:
- lib/index-tanked/active_record_defaults/search_result.rb
Instance Attribute Summary collapse
-
#missing_ids ⇒ Object
readonly
Returns the value of attribute missing_ids.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Attributes inherited from SearchResult
Instance Method Summary collapse
- #ids ⇒ Object
-
#initialize(query, index, model, options = {}) ⇒ SearchResult
constructor
A new instance of SearchResult.
- #inspect ⇒ Object
- #paginate(options = {}) ⇒ Object
- #records(options = {}) ⇒ Object
Methods inherited from SearchResult
#facets, #matches, #raw_result, #results, #search_time
Constructor Details
#initialize(query, index, model, options = {}) ⇒ SearchResult
Returns a new instance of SearchResult.
7 8 9 10 |
# File 'lib/index-tanked/active_record_defaults/search_result.rb', line 7 def initialize(query, index, model, ={}) super(query, index, ) @model = model end |
Instance Attribute Details
#missing_ids ⇒ Object (readonly)
Returns the value of attribute missing_ids.
5 6 7 |
# File 'lib/index-tanked/active_record_defaults/search_result.rb', line 5 def missing_ids @missing_ids end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
5 6 7 |
# File 'lib/index-tanked/active_record_defaults/search_result.rb', line 5 def model @model end |
Instance Method Details
#ids ⇒ Object
12 13 14 |
# File 'lib/index-tanked/active_record_defaults/search_result.rb', line 12 def ids results.map { |result| id = result['docid'].match(/^#{@model.name}:(\d+)$/); id && id[1].to_i }.compact.uniq end |
#inspect ⇒ Object
50 51 52 |
# File 'lib/index-tanked/active_record_defaults/search_result.rb', line 50 def inspect "<IndexTanked::ActiveRecordDefaults::SearchResult:#{object_id}, Query:'#{@query}'>" end |
#paginate(options = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/index-tanked/active_record_defaults/search_result.rb', line 34 def paginate(={}) = .clone @options[:page] = .delete(:page) || 1 @options[:per_page] = .delete(:per_page) || 15 begin WillPaginate::Collection.create(@options[:page], @options[:per_page]) do |pager| pager.replace(records()) pager.total_entries = results.total_entries unless pager.total_entries end rescue IndexTankedError @model.paginate() end end |
#records(options = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/index-tanked/active_record_defaults/search_result.rb', line 16 def records(={}) base = @model if defined?(Squirrel) && base.respond_to?(:scoped_without_squirrel) base = base.scoped_without_squirrel(:conditions => {:id => ids}) else base = base.scoped(:conditions => {:id => ids}) end records_found = base.all() @missing_ids = ids - records_found.map(&:id) begin if Configuration.missing_activerecord_ids_handler Configuration.missing_activerecord_ids_handler.call(@model.name, @missing_ids) end ensure return records_found end end |