algoliasearch 1.4.3 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ChangeLog +3 -0
- data/lib/algolia/index.rb +38 -2
- data/lib/algolia/version.rb +1 -1
- data/spec/client_spec.rb +38 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8320f64639625f110a727ff9020826427ebbc373
|
4
|
+
data.tar.gz: 56183ac910b91ecd25588d396b552a4e8d41aa43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06b994ce753c37cb70caa6c5ed61a3fa07f4e7fcf4e37427113873d03c444b6e21fa68c8e2f186937ce92256fc18c8ce7e9e856b56933046313e296f08515966
|
7
|
+
data.tar.gz: eb9d2669d3c719bb04e70ca8b0ec053d769c1bb66072386ce1dec0c1dcc27b86df99af957f7359cb16782cd6251a200edbae72dbf1aab17f026770f623e0d5db
|
data/ChangeLog
CHANGED
data/lib/algolia/index.rb
CHANGED
@@ -139,6 +139,25 @@ module Algolia
|
|
139
139
|
Algolia.client.get(Protocol.search_uri(name, query, encoded_params), :search)
|
140
140
|
end
|
141
141
|
|
142
|
+
class IndexBrowser
|
143
|
+
def initialize(name, params)
|
144
|
+
@name = name
|
145
|
+
@params = params
|
146
|
+
@cursor = params[:cursor] || params['cursor'] || nil
|
147
|
+
end
|
148
|
+
|
149
|
+
def browse(&block)
|
150
|
+
loop do
|
151
|
+
answer = Algolia.client.get(Protocol.browse_uri(@name, @params.merge({ :cursor => @cursor })), :read)
|
152
|
+
answer['hits'].each do |hit|
|
153
|
+
yield hit
|
154
|
+
end
|
155
|
+
@cursor = answer['cursor']
|
156
|
+
break if @cursor.nil?
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
142
161
|
#
|
143
162
|
# Browse all index content
|
144
163
|
#
|
@@ -146,8 +165,25 @@ module Algolia
|
|
146
165
|
# Page is zero-based and defaults to 0. Thus, to retrieve the 10th page you need to set page=9
|
147
166
|
# @param hitsPerPage: Pagination parameter used to select the number of hits per page. Defaults to 1000.
|
148
167
|
#
|
149
|
-
def browse(page =
|
150
|
-
|
168
|
+
def browse(page = nil, hitsPerPage = nil, &block)
|
169
|
+
if block_given?
|
170
|
+
params = {}
|
171
|
+
if page.is_a?(Hash)
|
172
|
+
params.merge!(page)
|
173
|
+
else
|
174
|
+
params[:page] = page unless page.nil?
|
175
|
+
end
|
176
|
+
if hitsPerPage.is_a?(Hash)
|
177
|
+
params.merge!(hitsPerPage)
|
178
|
+
else
|
179
|
+
params[:hitsPerPage] = hitsPerPage unless hitsPerPage.nil?
|
180
|
+
end
|
181
|
+
IndexBrowser.new(name, params).browse(&block)
|
182
|
+
else
|
183
|
+
page ||= 0
|
184
|
+
hitsPerPage ||= 1000
|
185
|
+
Algolia.client.get(Protocol.browse_uri(name, {:page => page, :hitsPerPage => hitsPerPage}), :read)
|
186
|
+
end
|
151
187
|
end
|
152
188
|
|
153
189
|
#
|
data/lib/algolia/version.rb
CHANGED
data/spec/client_spec.rb
CHANGED
@@ -738,8 +738,6 @@ describe 'Client' do
|
|
738
738
|
end
|
739
739
|
end
|
740
740
|
|
741
|
-
|
742
|
-
|
743
741
|
it "should send a custom batch" do
|
744
742
|
batch = [
|
745
743
|
{:action => "addObject", :indexName => @index.name, :body => { :objectID => "11", :email => "john@be.org" }},
|
@@ -749,5 +747,42 @@ describe 'Client' do
|
|
749
747
|
res = @index.search("@be.org")
|
750
748
|
res["hits"].length.should eq(2)
|
751
749
|
end
|
752
|
-
end
|
753
750
|
|
751
|
+
def test_browse(expected, *args)
|
752
|
+
@index.clear
|
753
|
+
@index.add_objects!(1.upto(1500).map { |i| { :objectID => i, :i => i } })
|
754
|
+
hits = {}
|
755
|
+
@index.browse(*args) do |hit|
|
756
|
+
hits[hit['objectID']] = true
|
757
|
+
end
|
758
|
+
hits.size.should eq(expected)
|
759
|
+
end
|
760
|
+
|
761
|
+
it "should browse the index using cursors" do
|
762
|
+
test_browse(1500)
|
763
|
+
test_browse(500, 1, 1000)
|
764
|
+
test_browse(0, 2, 1000)
|
765
|
+
end
|
766
|
+
|
767
|
+
it "should browse the index using cursors specifying hitsPerPage" do
|
768
|
+
test_browse(1500, { :hitsPerPage => 500 })
|
769
|
+
end
|
770
|
+
|
771
|
+
it "should browse the index using cursors specifying params" do
|
772
|
+
test_browse(1, { :hitsPerPage => 500, :numericFilters => 'i=42' })
|
773
|
+
test_browse(42, { :numericFilters => 'i<=42' })
|
774
|
+
end
|
775
|
+
|
776
|
+
it "should browse the index using cursors from a cursor" do
|
777
|
+
@index.clear
|
778
|
+
@index.add_objects!(1.upto(1500).map { |i| { :objectID => i, :i => i } })
|
779
|
+
answer = @index.browse(0, 1000)
|
780
|
+
|
781
|
+
hits = {}
|
782
|
+
@index.browse(:cursor => answer['cursor']) do |hit|
|
783
|
+
hits[hit['objectID']] = true
|
784
|
+
end
|
785
|
+
hits.size.should eq(500)
|
786
|
+
end
|
787
|
+
|
788
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: algoliasearch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Algolia
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05
|
11
|
+
date: 2015-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httpclient
|