algoliasearch 1.14.0 → 1.15.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: b6d01ca8470b386e201eafd5b2b9ddd4b7e27798
4
- data.tar.gz: aa1805c338e64d494faa766631f893b345c49a45
3
+ metadata.gz: 4652471c52a7730735419658326bb7202e00a8ef
4
+ data.tar.gz: bb43fe5aebc4ff687e2fcc51626c08de40c4f3b7
5
5
  SHA512:
6
- metadata.gz: 49325672a796719b69e9b55e712a7ebcfc40379455090269e540313a3d47498a1e6e51a7daad05565d90202897d909fe34540bf630d21e2ca50d0a30b3660a8d
7
- data.tar.gz: e042c97bf502f37e88081d72589c258dadb8059bd801a0d7f590ccee8cca19895f2cfc74b99c2f33b74daec248eec7791a594c9f83703fb206478aa215d94744
6
+ metadata.gz: 941a2837cb2c6a8da7d88c30829badbeb0a7eb2b7ad0e23ef0dd7349a16af7142c52bd8f01be51ccea9e47bdf01756ec200649717693da222fdf04362737697f
7
+ data.tar.gz: 710b30782cbf1b835b80b7c8dead3f5e84ac35113aa47ebc2cd4fa16e8dac2eaf68aa73c4fb160b47a984811658ce32e09fa9ec863cd1c59efbd24870b584ad3
data/ChangeLog CHANGED
@@ -1,5 +1,9 @@
1
1
  CHANGELOG
2
2
 
3
+ 2017-08-17 1.15.0
4
+ * Make delete_by_query not wait_task by default (also, make it mockable)
5
+ * Add a new delete_by_query! doing the last wait_task
6
+
3
7
  2017-07-31 1.14.0
4
8
  * Ability to override the underlying user-agent
5
9
 
data/Gemfile.lock CHANGED
@@ -32,8 +32,8 @@ GEM
32
32
  net-http-pipeline
33
33
  highline (1.6.21)
34
34
  httpclient (2.8.3)
35
- json (1.8.3)
36
- json (1.8.3-java)
35
+ json (1.8.6)
36
+ json (1.8.6-java)
37
37
  launchy (2.4.3)
38
38
  addressable (~> 2.3)
39
39
  launchy (2.4.3-java)
@@ -325,4 +325,4 @@ DEPENDENCIES
325
325
  webmock
326
326
 
327
327
  BUNDLED WITH
328
- 1.13.6
328
+ 1.15.3
data/README.md CHANGED
@@ -26,12 +26,19 @@ You can find the full reference on [Algolia's website](https://www.algolia.com/d
26
26
  1. **[Quick Start](#quick-start)**
27
27
 
28
28
  * [Initialize the client](#initialize-the-client)
29
- * [Push data](#push-data)
30
- * [Search](#search)
31
- * [Configure](#configure)
32
- * [Frontend search](#frontend-search)
33
29
 
34
- 1. **[Getting Help](#getting-help)**
30
+ 1. **[Push data](#push-data)**
31
+
32
+
33
+ 1. **[Configure](#configure)**
34
+
35
+
36
+ 1. **[Search](#search)**
37
+
38
+
39
+ 1. **[Search UI](#search-ui)**
40
+
41
+ * [index.html](#indexhtml)
35
42
 
36
43
 
37
44
 
@@ -41,6 +48,7 @@ You can find the full reference on [Algolia's website](https://www.algolia.com/d
41
48
 
42
49
 
43
50
 
51
+
44
52
  ## Install
45
53
 
46
54
  Install AlgoliaSearch using:
@@ -59,95 +67,133 @@ In 30 seconds, this quick start tutorial will show you how to index and search o
59
67
 
60
68
  ### Initialize the client
61
69
 
62
- You first need to initialize the client. For that you need your **Application ID** and **API Key**.
63
- You can find both of them on [your Algolia account](https://www.algolia.com/api-keys).
70
+ To begin, you will need to initialize the client. In order to do this you will need your **Application ID** and **API Key**.
71
+ You can find both on [your Algolia account](https://www.algolia.com/api-keys).
64
72
 
65
73
  ```ruby
66
74
  require 'rubygems'
67
75
  require 'algoliasearch'
68
76
 
69
- Algolia.init :application_id => "YourApplicationID",
70
- :api_key => "YourAPIKey"
77
+ Algolia.init application_id: 'YourApplicationID',
78
+ api_key: 'YourAPIKey'
71
79
  ```
72
80
 
73
- ### Push data
81
+ ## Push data
74
82
 
75
- Without any prior configuration, you can start indexing [500 contacts](https://github.com/algolia/algoliasearch-client-csharp/blob/master/contacts.json) in the ```contacts``` index using the following code:
83
+ Without any prior configuration, you can start indexing [500 contacts](https://raw.githubusercontent.com/algolia/datasets-public/master/contacts.json) in the ```contacts``` index using the following code:
76
84
  ```ruby
77
- index = Algolia::Index.new("contacts")
78
- batch = JSON.parse(File.read("contacts.json"))
85
+ index = Algolia::Index.new('contacts')
86
+ batch = JSON.parse(File.read('contacts.json'))
79
87
  index.add_objects(batch)
80
88
  ```
81
89
 
82
- ### Search
90
+ ## Configure
83
91
 
84
- You can now search for contacts using firstname, lastname, company, etc. (even with typos):
92
+ Settings can be customized to fine tune the search behavior. For example, you can add a custom sort by number of followers to further enhance the built-in relevance:
85
93
 
86
94
  ```ruby
87
- # search by firstname
88
- puts index.search('jimmie').to_json
89
- # search a firstname with typo
90
- puts index.search('jimie').to_json
91
- # search for a company
92
- puts index.search('california paint').to_json
93
- # search for a firstname & company
94
- puts index.search('jimmie paint').to_json
95
+ index.set_settings customRanking: ['desc(followers)']
95
96
  ```
96
97
 
97
- ### Configure
98
+ You can also configure the list of attributes you want to index by order of importance (most important first).
98
99
 
99
- Settings can be customized to tune the search behavior. For example, you can add a custom sort by number of followers to the already great built-in relevance:
100
+ **Note:** The Algolia engine is designed to suggest results as you type, which means you'll generally search by prefix.
101
+ In this case, the order of attributes is very important to decide which hit is the best:
100
102
 
101
103
  ```ruby
102
- index.set_settings({"customRanking" => ["desc(followers)"]})
104
+ index.set_settings searchableAttributes: %w(
105
+ lastname
106
+ firstname
107
+ company
108
+ email
109
+ city
110
+ address
111
+ )
103
112
  ```
104
113
 
105
- You can also configure the list of attributes you want to index by order of importance (first = most important):
114
+ ## Search
106
115
 
107
- **Note:** Since the engine is designed to suggest results as you type, you'll generally search by prefix.
108
- In this case the order of attributes is very important to decide which hit is the best:
116
+ You can now search for contacts using `firstname`, `lastname`, `company`, etc. (even with typos):
109
117
 
110
118
  ```ruby
111
- index.set_settings({"searchableAttributes" => ["lastname", "firstname", "company",
112
- "email", "city", "address"]})
119
+ # search by firstname
120
+ puts index.search('jimmie').to_json
121
+ # search a firstname with typo
122
+ puts index.search('jimie').to_json
123
+ # search for a company
124
+ puts index.search('california paint').to_json
125
+ # search for a firstname & company
126
+ puts index.search('jimmie paint').to_json
113
127
  ```
114
128
 
115
- ### Frontend search
129
+ ## Search UI
130
+
131
+ **Warning:** If you are building a web application, you may be more interested in using one of our
132
+ [frontend search UI librairies](https://www.algolia.com/doc/guides/search-ui/search-libraries/)
116
133
 
117
- **Note:** If you are building a web application, you may be more interested in using our [JavaScript client](https://github.com/algolia/algoliasearch-client-javascript) to perform queries.
134
+ The following example shows how to build a front-end search quickly using
135
+ [InstanSearch.js](https://community.algolia.com/instantsearch.js/)
118
136
 
119
- It brings two benefits:
120
- * Your users get a better response time by not going through your servers
121
- * It will offload unnecessary tasks from your servers
137
+ ### index.html
122
138
 
123
139
  ```html
124
- <script src="https://cdn.jsdelivr.net/algoliasearch/3/algoliasearch.min.js"></script>
125
- <script>
126
- var client = algoliasearch('ApplicationID', 'apiKey');
127
- var index = client.initIndex('indexName');
128
-
129
- // perform query "jim"
130
- index.search('jim', searchCallback);
131
-
132
- // the last optional argument can be used to add search parameters
133
- index.search(
134
- 'jim', {
135
- hitsPerPage: 5,
136
- facets: '*',
137
- maxValuesPerFacet: 10
138
- },
139
- searchCallback
140
+ <!doctype html>
141
+ <head>
142
+ <meta charset="UTF-8">
143
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/instantsearch.js/1/instantsearch.min.css">
144
+ </head>
145
+ <body>
146
+ <header>
147
+ <div>
148
+ <input id="search-input" placeholder="Search for products">
149
+ <!-- We use a specific placeholder in the input to guides users in their search. -->
150
+
151
+ </header>
152
+ <main>
153
+
154
+
155
+ </main>
156
+
157
+ <script type="text/html" id="hit-template">
158
+
159
+ <p class="hit-name">{{{_highlightResult.firstname.value}}} {{{_highlightResult.lastname.value}}}</p>
160
+
161
+ </script>
162
+
163
+ <script src="https://cdn.jsdelivr.net/instantsearch.js/1/instantsearch.min.js"></script>
164
+ <script src="app.js"></script>
165
+ </body>
166
+ ```
167
+
168
+ ### app.js
169
+
170
+ ```js
171
+ var search = instantsearch({
172
+ // Replace with your own values
173
+ appId: 'YourApplicationID',
174
+ apiKey: 'YourSearchOnlyAPIKey', // search only API key, no ADMIN key
175
+ indexName: 'contacts',
176
+ urlSync: true
177
+ });
178
+
179
+ search.addWidget(
180
+ instantsearch.widgets.searchBox({
181
+ container: '#search-input'
182
+ })
140
183
  );
141
184
 
142
- function searchCallback(err, content) {
143
- if (err) {
144
- console.error(err);
145
- return;
146
- }
185
+ search.addWidget(
186
+ instantsearch.widgets.hits({
187
+ container: '#hits',
188
+ hitsPerPage: 10,
189
+ templates: {
190
+ item: document.getElementById('hit-template').innerHTML,
191
+ empty: "We didn't find any results for the search <em>\"{{query}}\"</em>"
192
+ }
193
+ })
194
+ );
147
195
 
148
- console.log(content);
149
- }
150
- </script>
196
+ search.start();
151
197
  ```
152
198
 
153
199
  ## Getting Help
data/lib/algolia/index.rb CHANGED
@@ -405,13 +405,28 @@ module Algolia
405
405
  params.delete('attributesToRetrieve')
406
406
 
407
407
  params[:hitsPerPage] = 1000
408
+ params[:distinct] = false
408
409
  params[:attributesToRetrieve] = ['objectID']
410
+ last_task = nil
409
411
  loop do
410
412
  res = search(query, params)
411
413
  break if res['hits'].empty?
412
- res = delete_objects(res['hits'].map { |h| h['objectID'] })
413
- wait_task res['taskID']
414
+ last_task = delete_objects(res['hits'].map { |h| h['objectID'] })
415
+ break if res['hits'].size < 1000
414
416
  end
417
+ last_task
418
+ end
419
+
420
+ #
421
+ # Delete all objects matching a query and wait end of indexing
422
+ #
423
+ # @param query the query string
424
+ # @param params the optional query parameters
425
+ #
426
+ def delete_by_query!(query, params = nil)
427
+ res = delete_by_query(query, params)
428
+ wait_task(res['taskID']) if res
429
+ res
415
430
  end
416
431
 
417
432
  #
@@ -1,3 +1,3 @@
1
1
  module Algolia
2
- VERSION = "1.14.0"
2
+ VERSION = "1.15.0"
3
3
  end
data/spec/client_spec.rb CHANGED
@@ -241,7 +241,7 @@ describe 'Client' do
241
241
  @index.add_object({:firstname => "Robert1"})
242
242
  @index.add_object!({:firstname => "Robert2"})
243
243
  @index.search('')['nbHits'].should eq(2)
244
- @index.delete_by_query('rob')
244
+ @index.delete_by_query!('rob')
245
245
  @index.search('')['nbHits'].should eq(0)
246
246
  end
247
247
 
data/spec/mock_spec.rb CHANGED
@@ -21,6 +21,7 @@ describe 'With a mocked client' do
21
21
  index.browse
22
22
  index.clear
23
23
  index.delete
24
+ index.delete_by_query 'test'
24
25
  end
25
26
 
26
27
  after(:all) do
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.14.0
4
+ version: 1.15.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-07-31 00:00:00.000000000 Z
11
+ date: 2017-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient