Class: ActsAsFerret::MultiIndex

Inherits:
MultiIndexBase show all
Defined in:
lib/acts_as_ferret/multi_index.rb

Overview

This class can be used to search multiple physical indexes at once.

Instance Attribute Summary

Attributes inherited from MultiIndexBase

#logger

Instance Method Summary collapse

Methods inherited from MultiIndexBase

#ar_find, #determine_stored_fields, #initialize, #shared?

Methods included from FerretFindMethods

#ar_find, #count_records, #find_id_model_arrays, #find_ids, #find_records, #lazy_find, #scope_query_to_models

Constructor Details

This class inherits a constructor from ActsAsFerret::MultiIndexBase

Instance Method Details

#closeObject



100
101
102
103
# File 'lib/acts_as_ferret/multi_index.rb', line 100

def close
  @searcher.close if @searcher
  @reader.close if @reader
end

#doc(i) ⇒ Object Also known as: []



86
87
88
# File 'lib/acts_as_ferret/multi_index.rb', line 86

def doc(i)
  searcher[i]
end

#extract_stored_fields(doc, stored_fields) ⇒ Object



51
52
53
# File 'lib/acts_as_ferret/multi_index.rb', line 51

def extract_stored_fields(doc, stored_fields)
  ActsAsFerret::get_index_for(doc[:class_name]).extract_stored_fields(doc, stored_fields) unless stored_fields.blank?
end

#latest?Boolean

checks if all our sub-searchers still are up to date

Returns:

  • (Boolean)


71
72
73
74
75
76
77
78
79
# File 'lib/acts_as_ferret/multi_index.rb', line 71

def latest?
  #return false unless @reader
  # segfaults with 0.10.4 --> TODO report as bug @reader.latest?
  @reader and @reader.latest?
  #@sub_readers.each do |r| 
  #  return false unless r.latest? 
  #end
  #true
end

#process_query(query, options = {}) ⇒ Object



95
96
97
98
# File 'lib/acts_as_ferret/multi_index.rb', line 95

def process_query(query, options = {})
  query = query_parser.parse(query) if query.is_a?(String)
  return query
end

#query_parserObject



91
92
93
# File 'lib/acts_as_ferret/multi_index.rb', line 91

def query_parser
  @query_parser ||= Ferret::QueryParser.new(@options)
end

#search(query, options = {}) ⇒ Object



59
60
61
62
63
# File 'lib/acts_as_ferret/multi_index.rb', line 59

def search(query, options={})
  query = process_query(query, options)
  logger.debug "parsed query: #{query.to_s}"
  searcher.search(query, options)
end

#search_each(query, options = {}, &block) ⇒ Object



65
66
67
68
# File 'lib/acts_as_ferret/multi_index.rb', line 65

def search_each(query, options = {}, &block)
  query = process_query(query, options)
  searcher.search_each(query, options, &block)
end

#searcherObject



81
82
83
84
# File 'lib/acts_as_ferret/multi_index.rb', line 81

def searcher
  ensure_searcher
  @searcher
end

#total_hits(q, options = {}) ⇒ Object



55
56
57
# File 'lib/acts_as_ferret/multi_index.rb', line 55

def total_hits(q, options = {})
  search(q, options).total_hits
end