Class: ActsAsFerret::MultiIndexBase

Inherits:
Object
  • Object
show all
Includes:
FerretFindMethods
Defined in:
lib/acts_as_ferret/multi_index.rb

Overview

Base class for remote and local multi-indexes

Direct Known Subclasses

MultiIndex, RemoteMultiIndex

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  # 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(options)
  @logger = IndexLogger.new(ActsAsFerret::logger, "multi: #{indexes.map(&:index_name).join(',')}")
end

Instance Attribute Details

#loggerObject

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, options = {}, ar_options = {})
  limit = options.delete(:limit)
  offset = options.delete(:offset) || 0
  options[:limit] = :all
  total_hits, result = super query, options, ar_options  
  total_hits = result.size if ar_options[: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(options)
  return nil unless options.has_key?(:lazy)
  stored_fields = []
  @indexes.each do |index|
    stored_fields += index.determine_stored_fields(options)
  end
  return stored_fields.uniq
end

#shared?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/acts_as_ferret/multi_index.rb', line 49

def shared?
  false
end