Class: Findex::Search

Inherits:
Object
  • Object
show all
Defined in:
lib/findex/search.rb

Instance Method Summary collapse

Constructor Details

#initialize(root_path) ⇒ Search

Returns a new instance of Search.



3
4
5
6
7
# File 'lib/findex/search.rb', line 3

def initialize(root_path)
  @root_path = Pathname.new(root_path)
  @findex_path = @root_path + '.findex'
  setup
end

Instance Method Details

#query(query_terms) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/findex/search.rb', line 9

def query(query_terms)
  enquire = Xapian::Enquire.new(@db)
  add_prefixes(query_terms)
  query_terms.map! { |term| term =~ /\s+/ ? %("#{term}") : term }
  enquire.query = @query_parser.parse_query(query_terms.join(' '))
  mset = enquire.mset(0, @db.doccount)
  Enumerator.new do |y|
    mset.matches.each do |match|
      document = DocumentDecorator.new(match.document, @root_path)
      y << document
    end
  end
end