Class: UR::Search

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#facetsObject (readonly)

Returns the value of attribute facets.



12
13
14
# File 'lib/ur/search.rb', line 12

def facets
  @facets
end

#productsObject (readonly)

Returns the value of attribute products.



12
13
14
# File 'lib/ur/search.rb', line 12

def products
  @products
end

#solrObject (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_pageObject



42
43
44
# File 'lib/ur/search.rb', line 42

def next_page
  @solr.docs.next_page
end

#num_foundObject



30
31
32
# File 'lib/ur/search.rb', line 30

def num_found
  @solr.response['numFound'].to_i
end

#ok?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/ur/search.rb', line 34

def ok?
  @solr.ok?
end

#previous_pageObject



38
39
40
# File 'lib/ur/search.rb', line 38

def previous_page
  @solr.docs.previous_page
end