Class: Documentation::Searchers::Sunspot
- Inherits:
-
Abstract
- Object
- Abstract
- Documentation::Searchers::Sunspot
- Defined in:
- lib/documentation/searchers/sunspot.rb
Instance Method Summary collapse
- #delete(page) ⇒ Object
- #index(page) ⇒ Object
- #reset ⇒ Object
- #search(query, options = {}) ⇒ Object
- #setup ⇒ Object
Instance Method Details
#delete(page) ⇒ Object
21 22 23 |
# File 'lib/documentation/searchers/sunspot.rb', line 21 def delete(page) ::Sunspot.remove(page) end |
#index(page) ⇒ Object
17 18 19 |
# File 'lib/documentation/searchers/sunspot.rb', line 17 def index(page) ::Sunspot.index(page) end |
#reset ⇒ Object
25 26 27 |
# File 'lib/documentation/searchers/sunspot.rb', line 25 def reset ::Sunspot.remove_all(Documentation::Page) end |
#search(query, options = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/documentation/searchers/sunspot.rb', line 29 def search(query, = {}) # Default options [:page] ||= 1 [:per_page] ||= 15 result = ::Sunspot.search(Documentation::Page) do |search| search.keywords query, :highlight => true search.paginate :page => [:page], :per_page => [:per_page] end search_result = Documentation::SearchResult.new search_result.page = [:page].to_i search_result.per_page = [:per_page].to_i search_result.total_results = result.total search_result.query = query search_result.time = result.query_time search_result.raw_results = result.hits.inject(Hash.new) do |hash, hit| hash[hit.primary_key.to_i] = { :score => hit.score, :highlights => hit.highlights(:content).collect{|x| x.format{|word| "{{{#{word}}}}"}} } hash end # Return it search_result end |
#setup ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/documentation/searchers/sunspot.rb', line 5 def setup ::Sunspot.setup(Documentation::Page) do text :title, :boost => 2.0 text :content, :stored => true string :title, :stored => true string :permalink string :full_permalink time :created_at time :updated_at end end |