class Finder attr_reader :query def index @@index ||= Indexer.index end def initialize(raw_query,page=1,results_per_page=Picolena::ResultsPerPage) @query = Query.extract_from(raw_query) @raw_query= raw_query Indexer.ensure_index_existence @per_page=results_per_page @offset=(page.to_i-1)*results_per_page index_should_have_documents end def execute! @matching_documents=[] start=Time.now top_docs=index.search(query, :limit => @per_page, :offset=>@offset) top_docs.hits.each{|hit| index_id,score=hit.doc,hit.score begin found_doc=Document.new(index[index_id][:complete_path]) found_doc.matching_content=index.highlight(query, index_id, :field => :content, :excerpt_length => 80, :pre_tag => "<<", :post_tag => ">>" ) unless @raw_query=~/^\*+\.\w*$/ found_doc.score=score found_doc.index_id=index_id @matching_documents< 0 end end