Class: UR::Search
- Inherits:
-
Object
- Object
- UR::Search
- Defined in:
- lib/ur/search.rb
Overview
Search for products and populate from the metadata cache
Constant Summary collapse
- SEARCH_SERVICE_URL =
'http://services.ur.se/search'
Instance Attribute Summary collapse
-
#facets ⇒ Object
readonly
Returns the value of attribute facets.
-
#products ⇒ Object
readonly
Returns the value of attribute products.
-
#solr ⇒ Object
readonly
Returns the value of attribute solr.
Instance Method Summary collapse
-
#initialize(solr_params) ⇒ Search
constructor
A new instance of Search.
- #next_page ⇒ Object
- #num_found ⇒ Object
- #ok? ⇒ Boolean
- #previous_page ⇒ Object
Constructor Details
#initialize(solr_params) ⇒ Search
Returns a new instance of Search.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ur/search.rb', line 14 def initialize(solr_params) # Prepare the facets @products = [] @facets = {} @solr = nil begin solr = RSolr.connect :url => SEARCH_SERVICE_URL response = solr.find solr_params # Populate the products from the Metadata Cache @products = (response.ok? && response.docs.size > 0) ? Product.find(response.docs.map { |d| d.id }) : [] # Expose the Solr response @solr = response @solr.facets.map { |f| @facets[f.name] = f.items } if @solr.facets.size > 0 rescue RSolr::RequestError => e end end |
Instance Attribute Details
#facets ⇒ Object (readonly)
Returns the value of attribute facets.
12 13 14 |
# File 'lib/ur/search.rb', line 12 def facets @facets end |
#products ⇒ Object (readonly)
Returns the value of attribute products.
12 13 14 |
# File 'lib/ur/search.rb', line 12 def products @products end |
#solr ⇒ Object (readonly)
Returns the value of attribute solr.
12 13 14 |
# File 'lib/ur/search.rb', line 12 def solr @solr end |
Instance Method Details
#next_page ⇒ Object
47 48 49 |
# File 'lib/ur/search.rb', line 47 def next_page (ok? && !@solr.docs.nil?) ? @solr.docs.next_page : 0 end |
#num_found ⇒ Object
39 40 41 |
# File 'lib/ur/search.rb', line 39 def num_found (ok?) ? @solr.response['numFound'].to_i : 0 end |
#ok? ⇒ Boolean
35 36 37 |
# File 'lib/ur/search.rb', line 35 def ok? !@solr.nil? && @solr.ok? end |
#previous_page ⇒ Object
43 44 45 |
# File 'lib/ur/search.rb', line 43 def previous_page (ok? && !@solr.docs.nil?) ? @solr.docs.previous_page : 0 end |