algoliasearch 1.5.0 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog +3 -0
- data/README.md +13 -3
- data/lib/algolia/index.rb +21 -7
- data/lib/algolia/version.rb +1 -1
- data/spec/client_spec.rb +61 -58
- metadata +17 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f8a8ea00f71415bf0e2840c750d9122d14a0b14
|
4
|
+
data.tar.gz: 20f3cdce74f9bf324414263d8fb50e90f0ca933a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bdf0fb25764237fc16479a5d2f1faebf5f469cb979eaf9e3571b9fe70c3151ca8b40f24b7eee4a94b1bffe5f196d006becdc0ca8654e438567ec12e973623dd3
|
7
|
+
data.tar.gz: c94357b18b72c01a06ef07af02f45e5f4a01d16cb780af9c555a83321504719689563460691fc738dcafb5b0aa462c73b23cf408c7d2bb056c3368c241615cb9
|
data/ChangeLog
CHANGED
data/README.md
CHANGED
@@ -423,6 +423,8 @@ res = Algolia.multiple_queries([{:index_name => "categories", "query" => my_quer
|
|
423
423
|
puts res["results"]
|
424
424
|
```
|
425
425
|
|
426
|
+
The resulting JSON answer contains a ```results``` array storing the underlying queries answers. The answers order is the same than the requests order.
|
427
|
+
|
426
428
|
You can specify a strategy to optimize your multiple queries:
|
427
429
|
- **none**: Execute the sequence of queries until the end.
|
428
430
|
- **stopIfEnoughMatches**: Execute the sequence of queries until the number of hits is reached by the sum of hits.
|
@@ -569,7 +571,15 @@ index.clear_index
|
|
569
571
|
Wait indexing
|
570
572
|
-------------
|
571
573
|
|
572
|
-
All write operations
|
574
|
+
All write operations in Algolia are asynchronous by design.
|
575
|
+
|
576
|
+
It means that when you add or update an object to your index, our servers will
|
577
|
+
reply to your request with a `taskID` as soon as they understood the write
|
578
|
+
operation.
|
579
|
+
|
580
|
+
The actual insert and indexing will be done after replying to your code.
|
581
|
+
|
582
|
+
You can wait for a task to complete using the same method with a `!`.
|
573
583
|
|
574
584
|
For example, to wait for indexing of a new object:
|
575
585
|
```ruby
|
@@ -577,8 +587,8 @@ res = index.add_object!({"firstname" => "Jimmie",
|
|
577
587
|
"lastname" => "Barninger"})
|
578
588
|
```
|
579
589
|
|
580
|
-
|
581
|
-
|
590
|
+
If you want to ensure multiple objects have been indexed, you only need to check
|
591
|
+
the biggest `taskID` with `wait_task`.
|
582
592
|
|
583
593
|
Batch writes
|
584
594
|
-------------
|
data/lib/algolia/index.rb
CHANGED
@@ -150,7 +150,11 @@ module Algolia
|
|
150
150
|
loop do
|
151
151
|
answer = Algolia.client.get(Protocol.browse_uri(@name, @params.merge({ :cursor => @cursor })), :read)
|
152
152
|
answer['hits'].each do |hit|
|
153
|
-
|
153
|
+
if block.arity == 2
|
154
|
+
yield hit, @cursor
|
155
|
+
else
|
156
|
+
yield hit
|
157
|
+
end
|
154
158
|
end
|
155
159
|
@cursor = answer['cursor']
|
156
160
|
break if @cursor.nil?
|
@@ -161,17 +165,20 @@ module Algolia
|
|
161
165
|
#
|
162
166
|
# Browse all index content
|
163
167
|
#
|
164
|
-
# @param
|
165
|
-
#
|
168
|
+
# @param pageOrQueryParameters The hash of query parameters to use to browse
|
169
|
+
# To browse from a specific cursor, just add a ":cursor" parameters
|
170
|
+
#
|
171
|
+
# @DEPRECATED:
|
172
|
+
# @param pageOrQueryParameters Pagination parameter used to select the page to retrieve.
|
166
173
|
# @param hitsPerPage: Pagination parameter used to select the number of hits per page. Defaults to 1000.
|
167
174
|
#
|
168
|
-
def browse(
|
175
|
+
def browse(pageOrQueryParameters = nil, hitsPerPage = nil, &block)
|
169
176
|
if block_given?
|
170
177
|
params = {}
|
171
|
-
if
|
172
|
-
params.merge!(
|
178
|
+
if pageOrQueryParameters.is_a?(Hash)
|
179
|
+
params.merge!(pageOrQueryParameters)
|
173
180
|
else
|
174
|
-
params[:page] =
|
181
|
+
params[:page] = pageOrQueryParameters unless pageOrQueryParameters.nil?
|
175
182
|
end
|
176
183
|
if hitsPerPage.is_a?(Hash)
|
177
184
|
params.merge!(hitsPerPage)
|
@@ -186,6 +193,13 @@ module Algolia
|
|
186
193
|
end
|
187
194
|
end
|
188
195
|
|
196
|
+
#
|
197
|
+
# Browse a single page from a specific cursor
|
198
|
+
#
|
199
|
+
def browse_from(cursor, hitsPerPage = 1000)
|
200
|
+
Algolia.client.get(Protocol.browse_uri(name, { :cursor => cursor, :hitsPerPage => hitsPerPage }), :read)
|
201
|
+
end
|
202
|
+
|
189
203
|
#
|
190
204
|
# Get an object from this index
|
191
205
|
#
|
data/lib/algolia/version.rb
CHANGED
data/spec/client_spec.rb
CHANGED
@@ -4,7 +4,7 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
|
4
4
|
# avoid concurrent access to the same index
|
5
5
|
def safe_index_name(name)
|
6
6
|
return name if ENV['TRAVIS'].to_s != "true"
|
7
|
-
id = ENV['TRAVIS_JOB_NUMBER']
|
7
|
+
id = ENV['TRAVIS_JOB_NUMBER']
|
8
8
|
"#{name}_travis-#{id}"
|
9
9
|
end
|
10
10
|
|
@@ -225,10 +225,10 @@ describe 'Client' do
|
|
225
225
|
|
226
226
|
@index.add_object!({:firstname => "Robert"})
|
227
227
|
@index.search('')['nbHits'].should eq(1)
|
228
|
-
|
228
|
+
|
229
229
|
Algolia.copy_index!(safe_index_name("àlgol?a"), safe_index_name("àlgol?à"))
|
230
230
|
@index.delete_index!
|
231
|
-
|
231
|
+
|
232
232
|
index.search('')['nbHits'].should eq(1)
|
233
233
|
index.delete_index!
|
234
234
|
end
|
@@ -244,9 +244,9 @@ describe 'Client' do
|
|
244
244
|
|
245
245
|
@index.add_object!({:firstname => "Robert"})
|
246
246
|
@index.search('')['nbHits'].should eq(1)
|
247
|
-
|
247
|
+
|
248
248
|
Algolia.move_index!(safe_index_name("àlgol?a"), safe_index_name("àlgol?à"))
|
249
|
-
|
249
|
+
|
250
250
|
index.search('')['nbHits'].should eq(1)
|
251
251
|
index.delete_index
|
252
252
|
end
|
@@ -259,7 +259,7 @@ describe 'Client' do
|
|
259
259
|
|
260
260
|
res['hits'].size.should eq(1)
|
261
261
|
res['hits'][0]['firstname'].should eq("Robert")
|
262
|
-
end
|
262
|
+
end
|
263
263
|
|
264
264
|
it "should get logs" do
|
265
265
|
res = Algolia.get_logs(0, 20, true)
|
@@ -282,23 +282,23 @@ describe 'Client' do
|
|
282
282
|
request = { "requests" => [
|
283
283
|
{
|
284
284
|
"action" => "addObject",
|
285
|
-
"body" => {"firstname" => "Jimmie",
|
285
|
+
"body" => {"firstname" => "Jimmie",
|
286
286
|
"lastname" => "Barninger"}
|
287
287
|
},
|
288
288
|
{
|
289
289
|
"action" => "addObject",
|
290
|
-
"body" => {"firstname" => "Warren",
|
290
|
+
"body" => {"firstname" => "Warren",
|
291
291
|
"lastname" => "Speach"}
|
292
292
|
},
|
293
293
|
{
|
294
294
|
"action" => "updateObject",
|
295
|
-
"body" => {"firstname" => "Jimmie",
|
295
|
+
"body" => {"firstname" => "Jimmie",
|
296
296
|
"lastname" => "Barninger",
|
297
297
|
"objectID" => "43"}
|
298
298
|
},
|
299
299
|
{
|
300
300
|
"action" => "updateObject",
|
301
|
-
"body" => {"firstname" => "Warren",
|
301
|
+
"body" => {"firstname" => "Warren",
|
302
302
|
"lastname" => "Speach"},
|
303
303
|
"objectID" => "42"
|
304
304
|
}
|
@@ -396,7 +396,7 @@ describe 'Client' do
|
|
396
396
|
resEnd = Algolia.list_user_keys
|
397
397
|
is_include(resEnd['keys'], 'value', newKey['key']).should eq(false)
|
398
398
|
|
399
|
-
|
399
|
+
|
400
400
|
end
|
401
401
|
|
402
402
|
it "should check functions" do
|
@@ -414,7 +414,7 @@ describe 'Client' do
|
|
414
414
|
object = @index.get_object(res['hits'][0]['objectID'])
|
415
415
|
object['firstname'].should eq('Robert')
|
416
416
|
object = @index.get_object(res['hits'][0]['objectID'], 'firstname')
|
417
|
-
object['firstname'].should eq('Robert')
|
417
|
+
object['firstname'].should eq('Robert')
|
418
418
|
|
419
419
|
@index.save_object!({:firstname => "George", :objectID => "A/go/?a"})
|
420
420
|
res = @index.search('')
|
@@ -432,37 +432,37 @@ describe 'Client' do
|
|
432
432
|
|
433
433
|
it "Check attributes list_indexes:" do
|
434
434
|
res = Algolia::Index.all
|
435
|
-
res.should have_key('items')
|
436
|
-
res['items'][0].should have_key('name')
|
437
|
-
res['items'][0]['name'].should be_a(String)
|
438
|
-
res['items'][0].should have_key('createdAt')
|
439
|
-
res['items'][0]['createdAt'].should be_a(String)
|
440
|
-
res['items'][0].should have_key('updatedAt')
|
441
|
-
res['items'][0]['updatedAt'].should be_a(String)
|
442
|
-
res['items'][0].should have_key('entries')
|
443
|
-
res['items'][0]['entries'].should be_a(Integer)
|
444
|
-
res['items'][0].should have_key('pendingTask')
|
445
|
-
[true, false].should include(res['items'][0]['pendingTask'])
|
435
|
+
res.should have_key('items')
|
436
|
+
res['items'][0].should have_key('name')
|
437
|
+
res['items'][0]['name'].should be_a(String)
|
438
|
+
res['items'][0].should have_key('createdAt')
|
439
|
+
res['items'][0]['createdAt'].should be_a(String)
|
440
|
+
res['items'][0].should have_key('updatedAt')
|
441
|
+
res['items'][0]['updatedAt'].should be_a(String)
|
442
|
+
res['items'][0].should have_key('entries')
|
443
|
+
res['items'][0]['entries'].should be_a(Integer)
|
444
|
+
res['items'][0].should have_key('pendingTask')
|
445
|
+
[true, false].should include(res['items'][0]['pendingTask'])
|
446
446
|
end
|
447
447
|
|
448
448
|
it 'Check attributes search : ' do
|
449
449
|
res = @index.search('')
|
450
|
-
res.should have_key('hits')
|
450
|
+
res.should have_key('hits')
|
451
451
|
res['hits'].should be_a(Array)
|
452
|
-
res.should have_key('page')
|
453
|
-
res['page'].should be_a(Integer)
|
454
|
-
res.should have_key('nbHits')
|
455
|
-
res['nbHits'].should be_a(Integer)
|
456
|
-
res.should have_key('nbPages')
|
457
|
-
res['nbPages'].should be_a(Integer)
|
458
|
-
res.should have_key('hitsPerPage')
|
459
|
-
res['hitsPerPage'].should be_a(Integer)
|
460
|
-
res.should have_key('processingTimeMS')
|
461
|
-
res['processingTimeMS'].should be_a(Integer)
|
462
|
-
res.should have_key('query')
|
463
|
-
res['query'].should be_a(String)
|
464
|
-
res.should have_key('params')
|
465
|
-
res['params'].should be_a(String)
|
452
|
+
res.should have_key('page')
|
453
|
+
res['page'].should be_a(Integer)
|
454
|
+
res.should have_key('nbHits')
|
455
|
+
res['nbHits'].should be_a(Integer)
|
456
|
+
res.should have_key('nbPages')
|
457
|
+
res['nbPages'].should be_a(Integer)
|
458
|
+
res.should have_key('hitsPerPage')
|
459
|
+
res['hitsPerPage'].should be_a(Integer)
|
460
|
+
res.should have_key('processingTimeMS')
|
461
|
+
res['processingTimeMS'].should be_a(Integer)
|
462
|
+
res.should have_key('query')
|
463
|
+
res['query'].should be_a(String)
|
464
|
+
res.should have_key('params')
|
465
|
+
res['params'].should be_a(String)
|
466
466
|
end
|
467
467
|
|
468
468
|
it 'Check attributes delete_index : ' do
|
@@ -482,7 +482,7 @@ describe 'Client' do
|
|
482
482
|
task.should have_key('taskID')
|
483
483
|
task['taskID'].should be_a(Integer)
|
484
484
|
end
|
485
|
-
|
485
|
+
|
486
486
|
it 'Check attributes add object : ' do
|
487
487
|
task = @index.add_object({ :name => "John Doe", :email => "john@doe.org" })
|
488
488
|
task.should have_key('createdAt')
|
@@ -502,7 +502,7 @@ describe 'Client' do
|
|
502
502
|
#task.to_s.should eq("")
|
503
503
|
task.should have_key('objectID')
|
504
504
|
task['objectID'].should be_a(String)
|
505
|
-
task['objectID'].should eq("1")
|
505
|
+
task['objectID'].should eq("1")
|
506
506
|
end
|
507
507
|
|
508
508
|
it 'Check attributes partial update: ' do
|
@@ -592,7 +592,7 @@ describe 'Client' do
|
|
592
592
|
task.should have_key('status')
|
593
593
|
task['status'].should be_a(String)
|
594
594
|
task.should have_key('pendingTask')
|
595
|
-
[true, false].should include(task['pendingTask'])
|
595
|
+
[true, false].should include(task['pendingTask'])
|
596
596
|
end
|
597
597
|
|
598
598
|
it "Check add keys" do
|
@@ -656,28 +656,28 @@ describe 'Client' do
|
|
656
656
|
key.should eq(OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), 'my_api_key', 'public'))
|
657
657
|
key = Algolia.generate_secured_api_key('my_api_key', ['public', ['premium','vip']])
|
658
658
|
key.should eq(OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), 'my_api_key', 'public,(premium,vip)'))
|
659
|
-
end
|
659
|
+
end
|
660
660
|
|
661
661
|
it 'Check attributes multipleQueries' do
|
662
662
|
res = Algolia.multiple_queries([{:index_name => safe_index_name("àlgol?a"), "query" => ""}])
|
663
663
|
res.should have_key('results')
|
664
664
|
res['results'].should be_a(Array)
|
665
|
-
res['results'][0].should have_key('hits')
|
665
|
+
res['results'][0].should have_key('hits')
|
666
666
|
res['results'][0]['hits'].should be_a(Array)
|
667
|
-
res['results'][0].should have_key('page')
|
668
|
-
res['results'][0]['page'].should be_a(Integer)
|
669
|
-
res['results'][0].should have_key('nbHits')
|
670
|
-
res['results'][0]['nbHits'].should be_a(Integer)
|
671
|
-
res['results'][0].should have_key('nbPages')
|
672
|
-
res['results'][0]['nbPages'].should be_a(Integer)
|
673
|
-
res['results'][0].should have_key('hitsPerPage')
|
674
|
-
res['results'][0]['hitsPerPage'].should be_a(Integer)
|
675
|
-
res['results'][0].should have_key('processingTimeMS')
|
676
|
-
res['results'][0]['processingTimeMS'].should be_a(Integer)
|
677
|
-
res['results'][0].should have_key('query')
|
678
|
-
res['results'][0]['query'].should be_a(String)
|
679
|
-
res['results'][0].should have_key('params')
|
680
|
-
res['results'][0]['params'].should be_a(String)
|
667
|
+
res['results'][0].should have_key('page')
|
668
|
+
res['results'][0]['page'].should be_a(Integer)
|
669
|
+
res['results'][0].should have_key('nbHits')
|
670
|
+
res['results'][0]['nbHits'].should be_a(Integer)
|
671
|
+
res['results'][0].should have_key('nbPages')
|
672
|
+
res['results'][0]['nbPages'].should be_a(Integer)
|
673
|
+
res['results'][0].should have_key('hitsPerPage')
|
674
|
+
res['results'][0]['hitsPerPage'].should be_a(Integer)
|
675
|
+
res['results'][0].should have_key('processingTimeMS')
|
676
|
+
res['results'][0]['processingTimeMS'].should be_a(Integer)
|
677
|
+
res['results'][0].should have_key('query')
|
678
|
+
res['results'][0]['query'].should be_a(String)
|
679
|
+
res['results'][0].should have_key('params')
|
680
|
+
res['results'][0]['params'].should be_a(String)
|
681
681
|
end
|
682
682
|
|
683
683
|
it 'should handle disjunctive faceting' do
|
@@ -779,10 +779,13 @@ describe 'Client' do
|
|
779
779
|
answer = @index.browse(0, 1000)
|
780
780
|
|
781
781
|
hits = {}
|
782
|
-
@index.browse(:cursor => answer['cursor']) do |hit|
|
782
|
+
@index.browse(:cursor => answer['cursor']) do |hit, cursor|
|
783
783
|
hits[hit['objectID']] = true
|
784
|
+
cursor.should eq(answer['cursor'])
|
784
785
|
end
|
785
786
|
hits.size.should eq(500)
|
787
|
+
|
788
|
+
@index.browse_from(answer['cursor'])['hits'].size.should eq(500)
|
786
789
|
end
|
787
790
|
|
788
791
|
end
|
metadata
CHANGED
@@ -1,83 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: algoliasearch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Algolia
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httpclient
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '2.4'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.4'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: json
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 1.5.1
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 1.5.1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: travis
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rdoc
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - '>='
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
description: A simple Ruby client for the algolia.com REST API
|
@@ -89,8 +89,8 @@ extra_rdoc_files:
|
|
89
89
|
- LICENSE.txt
|
90
90
|
- README.md
|
91
91
|
files:
|
92
|
-
-
|
93
|
-
-
|
92
|
+
- .rspec
|
93
|
+
- .travis.yml
|
94
94
|
- ChangeLog
|
95
95
|
- Gemfile
|
96
96
|
- Gemfile.lock
|
@@ -121,17 +121,17 @@ require_paths:
|
|
121
121
|
- lib
|
122
122
|
required_ruby_version: !ruby/object:Gem::Requirement
|
123
123
|
requirements:
|
124
|
-
- -
|
124
|
+
- - '>='
|
125
125
|
- !ruby/object:Gem::Version
|
126
126
|
version: '0'
|
127
127
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- -
|
129
|
+
- - '>='
|
130
130
|
- !ruby/object:Gem::Version
|
131
131
|
version: '0'
|
132
132
|
requirements: []
|
133
133
|
rubyforge_project:
|
134
|
-
rubygems_version: 2.
|
134
|
+
rubygems_version: 2.0.14
|
135
135
|
signing_key:
|
136
136
|
specification_version: 4
|
137
137
|
summary: A simple Ruby client for the algolia.com REST API
|