Class: Frett::Search

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Search

Returns a new instance of Search.



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

def initialize(options = {})
  @options = Frett::Config.search.merge(:default_field => :content).
    merge(options)
end

Instance Method Details

#search(needle, path = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/frett/search.rb', line 8

def search(needle, path = nil)
  results = []
  adapter.read do |index|
    index.search_each(build_query(needle, path), :limit => Frett::Config.num_docs) do |doc_id, score|
      results.push result(index[doc_id])
    end
  end

  puts ( results.size == 1 ? "1 match" : "#{results.size} matches" ).white
  results.flatten.map { |result_line| puts result_line }
end