Class: ActsAsFerret::MultiIndexBase
- Inherits:
-
Object
- Object
- ActsAsFerret::MultiIndexBase
- Includes:
- FerretFindMethods
- Defined in:
- lib/acts_as_ferret/multi_index.rb
Overview
Base class for remote and local multi-indexes
Direct Known Subclasses
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
Instance Method Summary collapse
- #ar_find(query, options = {}, ar_options = {}) ⇒ Object
- #determine_stored_fields(options) ⇒ Object
-
#initialize(indexes, options = {}) ⇒ MultiIndexBase
constructor
A new instance of MultiIndexBase.
- #shared? ⇒ Boolean
Methods included from FerretFindMethods
#count_records, #find_id_model_arrays, #find_ids, #find_records, #lazy_find, #scope_query_to_models
Constructor Details
#initialize(indexes, options = {}) ⇒ MultiIndexBase
Returns a new instance of MultiIndexBase.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/acts_as_ferret/multi_index.rb', line 8 def initialize(indexes, = {}) # ensure all models indexes exist @indexes = indexes indexes.each { |i| i.ensure_index_exists } default_fields = indexes.inject([]) do |fields, idx| fields + [ idx.index_definition[:ferret][:default_field] ] end.flatten.uniq # Patch to pass an or_default setting on to ferret. # Without an or_default set, ferret will use OR queries by default. # This implementation will use OR if any model asks for OR, otherwise # AND. -- Paul Fitzpatrick, 11/1/2010 (contributed to public domain) or_default = indexes.select{|idx| idx.index_definition[:ferret][:or_default]}.size>0 @options = { :default_field => default_fields, :or_default => or_default }.update() @logger = IndexLogger.new(ActsAsFerret::logger, "multi: #{indexes.map(&:index_name).join(',')}") end |
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
6 7 8 |
# File 'lib/acts_as_ferret/multi_index.rb', line 6 def logger @logger end |
Instance Method Details
#ar_find(query, options = {}, ar_options = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/acts_as_ferret/multi_index.rb', line 28 def ar_find(query, = {}, = {}) limit = .delete(:limit) offset = .delete(:offset) || 0 [:limit] = :all total_hits, result = super query, , total_hits = result.size if [:conditions] # if limit && limit != :all # result = result[offset..limit+offset-1] # end [total_hits, result] end |
#determine_stored_fields(options) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/acts_as_ferret/multi_index.rb', line 40 def determine_stored_fields() return nil unless .has_key?(:lazy) stored_fields = [] @indexes.each do |index| stored_fields += index.determine_stored_fields() end return stored_fields.uniq end |
#shared? ⇒ Boolean
49 50 51 |
# File 'lib/acts_as_ferret/multi_index.rb', line 49 def shared? false end |