Class: Finder
- Inherits:
-
Object
- Object
- Finder
- Defined in:
- lib/picolena/templates/app/models/finder.rb
Instance Attribute Summary collapse
-
#query ⇒ Object
readonly
Returns the value of attribute query.
Class Method Summary collapse
Instance Method Summary collapse
- #execute! ⇒ Object
-
#executed? ⇒ Boolean
Returns true if it has been executed.
- #index ⇒ Object
-
#initialize(raw_query, by_date = false, page = 1, results_per_page = Picolena::ResultsPerPage) ⇒ Finder
constructor
A new instance of Finder.
Constructor Details
#initialize(raw_query, by_date = false, page = 1, results_per_page = Picolena::ResultsPerPage) ⇒ Finder
Returns a new instance of Finder.
8 9 10 11 12 13 14 15 16 |
# File 'lib/picolena/templates/app/models/finder.rb', line 8 def initialize(raw_query,by_date=false, 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 @by_date=by_date index_should_have_documents end |
Instance Attribute Details
#query ⇒ Object (readonly)
Returns the value of attribute query.
2 3 4 |
# File 'lib/picolena/templates/app/models/finder.rb', line 2 def query @query end |
Class Method Details
.reload! ⇒ Object
55 56 57 |
# File 'lib/picolena/templates/app/models/finder.rb', line 55 def self.reload! @@index = nil end |
Instance Method Details
#execute! ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/picolena/templates/app/models/finder.rb', line 18 def execute! @matching_documents=[] start=Time.now @total_hits = index.search_each(query, :limit => @per_page, :offset=>@offset, :sort => (sort_by_date if @by_date)){|index_id, 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 => ">>" ) found_doc.score=score @matching_documents<<found_doc rescue Errno::ENOENT #"File has been moved/deleted!" end } @executed=true @time_needed=Time.now-start end |
#executed? ⇒ Boolean
Returns true if it has been executed.
39 40 41 |
# File 'lib/picolena/templates/app/models/finder.rb', line 39 def executed? @executed end |