supernova 0.6.4 → 0.6.5

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.4
1
+ 0.6.5
@@ -82,6 +82,10 @@ class Supernova::Criteria
82
82
  merge_search_options :pagination, pagination_options
83
83
  end
84
84
 
85
+ def rows(number)
86
+ merge_search_options :pagination, :per_page => number
87
+ end
88
+
85
89
  def near(*coordinates)
86
90
  merge_search_options :geo_center, normalize_coordinates(*coordinates)
87
91
  end
@@ -166,11 +170,15 @@ class Supernova::Criteria
166
170
  end
167
171
 
168
172
  def per_page
169
- pagination_attribute_when_greater_zero(:per_page) || DEFAULT_PER_PAGE
173
+ ret = self.search_options[:pagination][:per_page] if self.search_options[:pagination]
174
+ ret = DEFAULT_PER_PAGE if ret.nil?
175
+ ret
170
176
  end
171
177
 
172
178
  def pagination_attribute_when_greater_zero(attribute)
173
- self.search_options[:pagination][attribute] if self.search_options[:pagination] && self.search_options[:pagination][attribute].to_i > 0
179
+ if self.search_options[:pagination] && self.search_options[:pagination][attribute].to_i > 0
180
+ self.search_options[:pagination][attribute]
181
+ end
174
182
  end
175
183
 
176
184
  def implement_in_subclass
@@ -168,10 +168,15 @@ class Supernova::SolrCriteria < Supernova::Criteria
168
168
 
169
169
  def execute
170
170
  response = Supernova::Solr.connection.post("select", :data => to_params)
171
- collection = Supernova::Collection.new(current_page, per_page, response["response"]["numFound"])
171
+ collection = Supernova::Collection.new(current_page, per_page == 0 ? 1 : per_page, response["response"]["numFound"])
172
172
  collection.original_response = response
173
173
  collection.facets = hashify_facets_from_response(response)
174
174
  collection.replace(build_docs(response["response"]["docs"]))
175
175
  collection
176
176
  end
177
+
178
+ def ids
179
+ select("id")
180
+ execute.map! { |h| h["id"].split("/").last.to_i }
181
+ end
177
182
  end
@@ -252,6 +252,25 @@ describe "Solr" do
252
252
  end
253
253
  end
254
254
 
255
+ describe "#ids" do
256
+ it "only returns the ids in a collection" do
257
+ result = new_criteria.ids
258
+ result.should be_kind_of(Supernova::Collection)
259
+ result.should == [1, 2]
260
+ result.total_entries.should == 2
261
+ end
262
+
263
+ it "does include facets" do
264
+ new_criteria.facet_fields(:enabled_b).ids.facets.should == { "enabled_b" => { "true" => 1, "false" => 1 } }
265
+ end
266
+
267
+ it "returns 0 rows" do
268
+ response = new_criteria.rows(0).facet_fields(:enabled_b).ids
269
+ response.should be_empty
270
+ response.facets.should == { "enabled_b" => { "true" => 1, "false" => 1 } }
271
+ end
272
+ end
273
+
255
274
  describe "with mapping" do
256
275
  before(:each) do
257
276
  @clazz = Class.new(Supernova::SolrIndexer)
@@ -102,6 +102,20 @@ describe "Supernova::Criteria" do
102
102
  scope.paginate(:page => 9, :per_page => 2).search_options[:pagination].should == { :page => 9, :per_page => 2 }
103
103
  end
104
104
 
105
+ it "sets per_page to number of rows when rows specified" do
106
+ scope.rows(0).search_options[:pagination].should == { :per_page => 0 }
107
+ end
108
+
109
+ describe "#per_page" do
110
+ it "allows setting of pagination to 0" do
111
+ scope.paginate(:per_page => 0).per_page.should == 0
112
+ end
113
+
114
+ it "" do
115
+ scope.paginate(:per_page => nil).per_page.should == 25
116
+ end
117
+ end
118
+
105
119
  describe "#without" do
106
120
  it "sets the correct without filter" do
107
121
  scope.without(:user_id => 1).filters[:without].should == { :user_id => [1] }
@@ -208,6 +208,24 @@ describe Supernova::SolrCriteria do
208
208
  criteria.attribute_mapping(:artist_name => { :type => :string }).solr_field_from_field(:artist_name).should == "artist_name_s"
209
209
  end
210
210
  end
211
+
212
+ describe "#ids" do
213
+ it "sets the select fields to id only" do
214
+ criteria.should_receive(:select).with("id")
215
+ criteria.stub!(:execute).and_return([])
216
+ criteria.ids
217
+ end
218
+
219
+ it "calls execute" do
220
+ criteria.should_receive(:execute).and_return([])
221
+ criteria.ids
222
+ end
223
+
224
+ it "maps the id hashes to ids" do
225
+ criteria.stub(:execute).and_return([ { "id" => "offer/1" }, { "id" => "offer/3" } ])
226
+ criteria.ids
227
+ end
228
+ end
211
229
 
212
230
  describe "#execute" do
213
231
  let(:params) { double("params") }
@@ -504,8 +522,8 @@ describe Supernova::SolrCriteria do
504
522
  criteria.paginate(:page => 3, :per_page => nil).per_page.should == 25
505
523
  end
506
524
 
507
- it "returns 25 when set to 0" do
508
- criteria.paginate(:page => 3, :per_page => 0).per_page.should == 25
525
+ it "returns 0 when set to 0" do
526
+ criteria.paginate(:page => 3, :per_page => 0).per_page.should == 0
509
527
  end
510
528
 
511
529
  it "returns the custom value when set" do
data/supernova.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{supernova}
8
- s.version = "0.6.4"
8
+ s.version = "0.6.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tobias Schwab"]
12
- s.date = %q{2011-08-23}
12
+ s.date = %q{2011-09-01}
13
13
  s.default_executable = %q{start_solr}
14
14
  s.description = %q{Unified search scopes}
15
15
  s.email = %q{tobias.schwab@dynport.de}
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: supernova
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 4
10
- version: 0.6.4
9
+ - 5
10
+ version: 0.6.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tobias Schwab
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-23 00:00:00 +02:00
18
+ date: 2011-09-01 00:00:00 +02:00
19
19
  default_executable: start_solr
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency