Class: ActiveLucene::Searcher
- Inherits:
-
IndexSearcher
- Object
- IndexSearcher
- ActiveLucene::Searcher
- Includes:
- Index
- Defined in:
- lib/active_lucene/searcher.rb
Constant Summary
Constants included from Index
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#total_pages ⇒ Object
readonly
Returns the value of attribute total_pages.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Searcher
constructor
A new instance of Searcher.
- #search(param) ⇒ Object
Methods included from Index
Constructor Details
#initialize ⇒ Searcher
Returns a new instance of Searcher.
7 8 9 |
# File 'lib/active_lucene/searcher.rb', line 7 def initialize super directory, true end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
5 6 7 |
# File 'lib/active_lucene/searcher.rb', line 5 def attributes @attributes end |
#total_pages ⇒ Object (readonly)
Returns the value of attribute total_pages.
5 6 7 |
# File 'lib/active_lucene/searcher.rb', line 5 def total_pages @total_pages end |
Class Method Details
.search(param) ⇒ Object
11 12 13 14 15 |
# File 'lib/active_lucene/searcher.rb', line 11 def self.search(param) returning new do |searcher| searcher.search param end end |
Instance Method Details
#search(param) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/active_lucene/searcher.rb', line 17 def search(param) query = Query.for(param) top_docs = super(query, nil, Document::PER_PAGE) @attributes = top_docs.scoreDocs.map do |score_doc| attributes = {} doc(score_doc.doc).fields.each do |field| attributes.store field.name, field.string_value highlight = Highlighter.new(QueryScorer.new(query)).get_best_fragment(Analyzer.new, ALL, field.string_value) attributes[:highlight] = highlight if highlight end attributes end @total_pages = (top_docs.totalHits / Document::PER_PAGE.to_f).ceil end |