Class: Ferret::Search::Searcher
- Inherits:
-
Object
- Object
- Ferret::Search::Searcher
- Defined in:
- ext/r_search.c
Overview
Summary
The Searcher class basically performs the task that Ferret was built for. It searches the index. To search the index the Searcher class wraps an IndexReader so many of the tasks that you can perform on an IndexReader are also available on a searcher including, most importantly, accessing stored documents.
The main methods that you need to know about when using a Searcher are the search methods. There is the Searcher#search_each method which iterates through the results by document id and score and there is the Searcher#search method which returns a TopDocs object. Another important difference to note is that the Searcher#search_each method normalizes the score to a value in the range 0.0..1.0 if the max_score is greater than 1.0. Searcher#search does not. Apart from that they take the same parameters and work the same way.
Example
searcher = Searcher.new("/path/to/index")
searcher.search_each(TermQuery.new(:content, "ferret")
:filter => RangeFilter.new(:date, :< => "2006"),
:sort => "date DESC, title") do |doc_id, score|
puts "#{searcher[doc_id][title] scored #{score}"
end