algoliasearch 1.16.0 → 1.17.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bb21e712b8f13f4624b33858edbe573acf33a7d1
4
- data.tar.gz: 3bb19d2382c63494c56b43266fdf0898da59e9c9
3
+ metadata.gz: b003d66ce48ed84c00beee6a9e93bb65c704ca2e
4
+ data.tar.gz: f9ae3ed72cd92b351684a22b45ef9ccd2f486fc7
5
5
  SHA512:
6
- metadata.gz: b6324fd4f0dc64f44edf75a8985004cc230de0ad418e114224b90e115f2feec52fa0389328904fa58188ea4e853e2994866cbbb498d479956a50b60f0a91fe69
7
- data.tar.gz: 894a5a056b54195fa7b71703915ad58159e9f8b717487008d7395f255fd79a7659b36285caa345666fa0811a0d5cac0b4a774be32471f41b11f3293b0f97f98e
6
+ metadata.gz: e72ac4175524739045f3fdb369f2e65c29714744c63af237542f0f7086b2ec6acd19aa17736793bdf28a1e545488005724ce3d6437560a73175c06bc712aa20a
7
+ data.tar.gz: 3aa8a7e84b25d0487ac8cb7c6545c26b79fb5fa5b5b78f80e146c54cb0897457880cb68b834afd9a5f5e1239763a7b33c874e965e73b54d4736e4b3a21259ad0
data/ChangeLog CHANGED
@@ -1,5 +1,8 @@
1
1
  CHANGELOG
2
2
 
3
+ 2017-10-10 1.17.0
4
+ * New delete_by method
5
+
3
6
  2017-09-14 1.16.0
4
7
  * New Query Rules API
5
8
 
data/lib/algolia/index.rb CHANGED
@@ -434,6 +434,29 @@ module Algolia
434
434
  res
435
435
  end
436
436
 
437
+ #
438
+ # Delete all objects matching a query (doesn't work with actual text queries)
439
+ # This method deletes every record matching the filters provided
440
+ #
441
+ # @param params query parameters
442
+ #
443
+ def delete_by(params)
444
+ raise ArgumentError.new('params cannot be nil, use the `clear` method to wipe the entire index') if params.nil?
445
+ params = sanitized_delete_by_query_params(params)
446
+ client.post(Protocol.delete_by_uri(name), params.to_json)
447
+ end
448
+
449
+ #
450
+ # Delete all objects matching a query (doesn't work with actual text queries)
451
+ # This method deletes every record matching the filters provided and waits for the end of indexing
452
+ # @param params query parameters
453
+ #
454
+ def delete_by!(params)
455
+ res = delete_by(params)
456
+ wait_task(res['taskID']) if res
457
+ res
458
+ end
459
+
437
460
  #
438
461
  # Delete the index content
439
462
  #
@@ -167,5 +167,9 @@ module Algolia
167
167
  "#{rules_uri(index)}/batch"
168
168
  end
169
169
 
170
+ def Protocol.delete_by_uri(index)
171
+ "#{index_uri(index)}/deleteByQuery"
172
+ end
173
+
170
174
  end
171
175
  end
@@ -1,3 +1,3 @@
1
1
  module Algolia
2
- VERSION = "1.16.0"
2
+ VERSION = "1.17.0"
3
3
  end
data/spec/client_spec.rb CHANGED
@@ -249,6 +249,31 @@ describe 'Client' do
249
249
  expect { @index.delete_by_query(nil) }.to raise_error(ArgumentError)
250
250
  end
251
251
 
252
+ context 'delete_by' do
253
+ it 'should not wipe the entire index' do
254
+ expect { @index.delete_by(nil) }.to raise_error(ArgumentError)
255
+ end
256
+
257
+ it 'should fail with query passed' do
258
+ @index.clear
259
+ @index.add_object({:firstname => 'Robert1'})
260
+ @index.add_object!({:firstname => 'Robert2'})
261
+ @index.search('')['nbHits'].should eq(2)
262
+ expect { @index.delete_by({ 'query' => 'abc' }) }.to raise_error(Algolia::AlgoliaProtocolError)
263
+ @index.search('')['nbHits'].should eq(2)
264
+ end
265
+
266
+ it 'should work with filters' do
267
+ @index.clear
268
+ @index.set_settings!({:attributesForFaceting => ['firstname']})
269
+ @index.add_object({:firstname => 'Robert1'})
270
+ @index.add_object!({:firstname => 'Robert2'})
271
+ @index.search('')['nbHits'].should eq(2)
272
+ @index.delete_by!({ 'filters' => 'firstname:Robert1' })
273
+ @index.search('')['nbHits'].should eq(1)
274
+ end
275
+ end
276
+
252
277
  it "should copy the index" do
253
278
  index = Algolia::Index.new(safe_index_name("àlgol?à"))
254
279
  begin
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.16.0
4
+ version: 1.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Algolia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-14 00:00:00.000000000 Z
11
+ date: 2017-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
131
  version: '0'
132
132
  requirements: []
133
133
  rubyforge_project:
134
- rubygems_version: 2.6.13
134
+ rubygems_version: 2.6.10
135
135
  signing_key:
136
136
  specification_version: 4
137
137
  summary: A simple Ruby client for the algolia.com REST API