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
# 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
  @options = {
    :default_field => default_fields
  }.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



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/acts_as_ferret/multi_index.rb', line 21

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



33
34
35
36
37
38
39
40
# File 'lib/acts_as_ferret/multi_index.rb', line 33

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)


42
43
44
# File 'lib/acts_as_ferret/multi_index.rb', line 42

def shared?
  false
end