ur-product 0.7 → 0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/ur/search.rb +22 -17
  2. metadata +3 -3
data/lib/ur/search.rb CHANGED
@@ -12,35 +12,40 @@ module UR
12
12
  attr_reader :products, :solr, :facets
13
13
 
14
14
  def initialize(solr_params)
15
- solr = RSolr.connect :url => SEARCH_SERVICE_URL
16
- response = solr.find solr_params
17
-
18
- # Populate the products from the Metadata Cache
19
- @products = (response.ok? && response.docs.size > 0) ?
20
- Product.find(response.docs.map { |d| d.id }) : []
21
-
22
- # Expose the Solr response
23
- @solr = response
24
-
25
15
  # Prepare the facets
16
+ @products = []
26
17
  @facets = {}
27
- @solr.facets.map { |f| @facets[f.name] = f.items } if @solr.facets.size > 0
18
+ @solr = nil
19
+
20
+ begin
21
+ solr = RSolr.connect :url => SEARCH_SERVICE_URL
22
+ response = solr.find solr_params
23
+
24
+ # Populate the products from the Metadata Cache
25
+ @products = (response.ok? && response.docs.size > 0) ?
26
+ Product.find(response.docs.map { |d| d.id }) : []
27
+
28
+ # Expose the Solr response
29
+ @solr = response
30
+ @solr.facets.map { |f| @facets[f.name] = f.items } if @solr.facets.size > 0
31
+ rescue RSolr::RequestError => e
32
+ end
28
33
  end
29
34
 
30
- def num_found
31
- @solr.response['numFound'].to_i
35
+ def ok?
36
+ !@solr.nil? && @solr.ok?
32
37
  end
33
38
 
34
- def ok?
35
- @solr.ok?
39
+ def num_found
40
+ (ok?) ? @solr.response['numFound'].to_i : 0
36
41
  end
37
42
 
38
43
  def previous_page
39
- @solr.docs.previous_page
44
+ (ok? && !@solr.docs.nil?) ? @solr.docs.previous_page : 0
40
45
  end
41
46
 
42
47
  def next_page
43
- @solr.docs.next_page
48
+ (ok? && !@solr.docs.nil?) ? @solr.docs.next_page : 0
44
49
  end
45
50
  end
46
51
  end
metadata CHANGED
@@ -4,8 +4,8 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 7
8
- version: "0.7"
7
+ - 8
8
+ version: "0.8"
9
9
  platform: ruby
10
10
  authors:
11
11
  - Peter Hellberg
@@ -13,7 +13,7 @@ autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
15
 
16
- date: 2010-05-20 00:00:00 +02:00
16
+ date: 2010-05-21 00:00:00 +02:00
17
17
  default_executable:
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency