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 |
# File 'lib/ur/search.rb', line 14 def initialize(solr_params) 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 # Prepare the facets @facets = {} @solr.facets.map { |f| @facets[f.name] = f.items } if @solr.facets.size > 0 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
42 43 44 |
# File 'lib/ur/search.rb', line 42 def next_page @solr.docs.next_page end |
#num_found ⇒ Object
30 31 32 |
# File 'lib/ur/search.rb', line 30 def num_found @solr.response['numFound'].to_i end |
#ok? ⇒ Boolean
34 35 36 |
# File 'lib/ur/search.rb', line 34 def ok? @solr.ok? end |
#previous_page ⇒ Object
38 39 40 |
# File 'lib/ur/search.rb', line 38 def previous_page @solr.docs.previous_page end |