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



107
108
109
110
# File 'lib/acts_as_ferret/multi_index.rb', line 107

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

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



93
94
95
# File 'lib/acts_as_ferret/multi_index.rb', line 93

def doc(i)
  searcher[i]
end

#extract_stored_fields(doc, stored_fields) ⇒ Object



58
59
60
# File 'lib/acts_as_ferret/multi_index.rb', line 58

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)


78
79
80
81
82
83
84
85
86
# File 'lib/acts_as_ferret/multi_index.rb', line 78

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



102
103
104
105
# File 'lib/acts_as_ferret/multi_index.rb', line 102

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

#query_parserObject



98
99
100
# File 'lib/acts_as_ferret/multi_index.rb', line 98

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

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



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

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



72
73
74
75
# File 'lib/acts_as_ferret/multi_index.rb', line 72

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

#searcherObject



88
89
90
91
# File 'lib/acts_as_ferret/multi_index.rb', line 88

def searcher
  ensure_searcher
  @searcher
end

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



62
63
64
# File 'lib/acts_as_ferret/multi_index.rb', line 62

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