algoliasearch 1.2.9 → 1.2.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -2
- data/ChangeLog +6 -1
- data/README.md +126 -36
- data/algoliasearch.gemspec +2 -2
- data/lib/algolia/client.rb +34 -25
- data/lib/algolia/index.rb +1 -1
- data/lib/algolia/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df5a732fe0627231c87d9015404183714d411ca8
|
4
|
+
data.tar.gz: 3c90c3e9c12cafa3cb37d254acf723c3a210f48b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3a164a8ca1699b0f34801431985fd475a1440ca04de278cf81fe7640b5bebd44a5ee86b92a0e60a967f0e777f51e06afac3a689381581a9aa71d0cd5f101f50
|
7
|
+
data.tar.gz: e51c1cd7aef502ee8ea4d6eecff24e22be7ef957590d008df148225590857eb797ec27de59b8c4741798adcd0fe90897c5535c0c870836ad0e705616f64195c7
|
data/.travis.yml
CHANGED
@@ -9,7 +9,9 @@ rvm:
|
|
9
9
|
- 1.9.3
|
10
10
|
- jruby
|
11
11
|
- rbx-2
|
12
|
+
install:
|
13
|
+
- bundle install
|
12
14
|
env:
|
13
15
|
global:
|
14
|
-
- secure:
|
15
|
-
- secure:
|
16
|
+
- secure: OFKp0J81VrKXfpQZWkwSfsG/knN4tr45yDAGekFy4FKcA6Ra6EqDUzcY1MVrkKq9YRUgLJRfjgqF3Ei0cm2qMo1dy5XUG/fY8upTVdQK2Nm1qfbjnh70+vnYpHidHg9pEI8QROwsM7n19QoT16j1af4UinGFE/HBiJpuXcABuLw=
|
17
|
+
- secure: Jkc/DnS1knCf0fO3qUxaExoEPEEuTFcmJGP/DkOZ5tnMSro8pjgzXIIzMaQSoRO4B7Hv0o7NzNTqNV6/KgB3jLlsj4dQtjkTnZ21Uk0sah5wZpWyC6QhtuIv1yA2utIsNLygU9WDoyD+V9EwuYrLNone1zSGIclAjlPO4xCYo6E=
|
data/ChangeLog
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
|
3
|
-
2014-
|
3
|
+
2014-08-22 1.2.10
|
4
4
|
|
5
|
+
* Using Digest to remove "Digest::Digest is deprecated; Use Digest" warning (author: @dglancy)
|
6
|
+
|
7
|
+
2014-07-10 1.2.9
|
8
|
+
|
9
|
+
* Expose connect_timeout, receive_timeout and send_timeout
|
5
10
|
* Add new 'delete_by_query' method to delete all objects matching a specific query
|
6
11
|
* Add new 'get_objects' method to retrieve a list of objects from a single API call
|
7
12
|
* Add a helper to perform disjunctive faceting
|
data/README.md
CHANGED
@@ -3,8 +3,6 @@ Algolia Search API Client for Ruby
|
|
3
3
|
|
4
4
|
|
5
5
|
|
6
|
-
|
7
|
-
|
8
6
|
[Algolia Search](http://www.algolia.com) is a search API that provides hosted full-text, numerical and faceted search.
|
9
7
|
Algolia’s Search API makes it easy to deliver a great search experience in your apps & websites providing:
|
10
8
|
|
@@ -19,18 +17,18 @@ Algolia’s Search API makes it easy to deliver a great search experience in you
|
|
19
17
|
|
20
18
|
This Ruby client let you easily use the Algolia Search API from your backend. It wraps [Algolia's REST API](http://www.algolia.com/doc/rest_api).
|
21
19
|
|
22
|
-
|
23
20
|
[![Build Status](https://travis-ci.org/algolia/algoliasearch-client-ruby.png?branch=master)](https://travis-ci.org/algolia/algoliasearch-client-ruby) [![Gem Version](https://badge.fury.io/rb/algoliasearch.png)](http://badge.fury.io/rb/algoliasearch) [![Code Climate](https://codeclimate.com/github/algolia/algoliasearch-client-ruby.png)](https://codeclimate.com/github/algolia/algoliasearch-client-ruby) [![Coverage Status](https://coveralls.io/repos/algolia/algoliasearch-client-ruby/badge.png)](https://coveralls.io/r/algolia/algoliasearch-client-ruby)
|
24
21
|
|
25
22
|
|
26
23
|
|
27
24
|
Table of Content
|
28
|
-
|
25
|
+
================
|
29
26
|
**Get started**
|
30
27
|
|
31
28
|
1. [Setup](#setup)
|
32
29
|
1. [Quick Start](#quick-start)
|
33
|
-
1. [Online documentation](#
|
30
|
+
1. [Online documentation](#documentation)
|
31
|
+
1. [Tutorials](#tutorials)
|
34
32
|
|
35
33
|
**Commands reference**
|
36
34
|
|
@@ -39,8 +37,9 @@ Table of Content
|
|
39
37
|
1. [Search](#search)
|
40
38
|
1. [Get an object](#get-an-object)
|
41
39
|
1. [Delete an object](#delete-an-object)
|
40
|
+
1. [Delete by query](#delete-by-query)
|
42
41
|
1. [Index settings](#index-settings)
|
43
|
-
1. [List
|
42
|
+
1. [List indices](#list-indices)
|
44
43
|
1. [Delete an index](#delete-an-index)
|
45
44
|
1. [Clear an index](#clear-an-index)
|
46
45
|
1. [Wait indexing](#wait-indexing)
|
@@ -74,6 +73,10 @@ Algolia.init :application_id => "YourApplicationID",
|
|
74
73
|
|
75
74
|
|
76
75
|
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
|
77
80
|
Quick Start
|
78
81
|
-------------
|
79
82
|
|
@@ -116,27 +119,63 @@ puts index.search('jim').to_json
|
|
116
119
|
```
|
117
120
|
|
118
121
|
|
122
|
+
**Notes:** If you are building a web application, you may be more interested in using our [JavaScript client](https://github.com/algolia/algoliasearch-client-js) to perform queries. It brings two benefits:
|
123
|
+
* your users get a better response time by avoiding to go through your servers,
|
124
|
+
* it will offload your servers of unnecessary tasks.
|
125
|
+
|
126
|
+
```html
|
127
|
+
<script type="text/javascript" src="//path/to/algoliasearch.min.js"></script>
|
128
|
+
<script type="text/javascript">
|
129
|
+
var client = new AlgoliaSearch("YourApplicationID", "YourSearchOnlyAPIKey");
|
130
|
+
var index = client.initIndex('YourIndexName');
|
119
131
|
|
132
|
+
function searchCallback(success, content) {
|
133
|
+
if (success) {
|
134
|
+
console.log(content);
|
135
|
+
}
|
136
|
+
}
|
120
137
|
|
121
|
-
|
122
|
-
|
138
|
+
// perform query "jim"
|
139
|
+
index.search("jim", searchCallback);
|
123
140
|
|
124
|
-
|
125
|
-
*
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
141
|
+
// the last optional argument can be used to add search parameters
|
142
|
+
index.search("jim", searchCallback, { hitsPerPage: 5, facets: '*', maxValuesPerFacet: 10 });
|
143
|
+
</script>
|
144
|
+
```
|
145
|
+
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
Documentation
|
152
|
+
================
|
153
|
+
|
154
|
+
Check our [online documentation](http://www.algolia.com/doc/guides/ruby):
|
155
|
+
* [Initial Import](http://www.algolia.com/doc/guides/ruby#InitialImport)
|
156
|
+
* [Ranking & Relevance](http://www.algolia.com/doc/guides/ruby#RankingRelevance)
|
157
|
+
* [Indexing](http://www.algolia.com/doc/guides/ruby#Indexing)
|
158
|
+
* [Search](http://www.algolia.com/doc/guides/ruby#Search)
|
159
|
+
* [Sorting](http://www.algolia.com/doc/guides/ruby#Sorting)
|
160
|
+
* [Filtering](http://www.algolia.com/doc/guides/ruby#Filtering)
|
161
|
+
* [Faceting](http://www.algolia.com/doc/guides/ruby#Faceting)
|
162
|
+
* [Geo-Search](http://www.algolia.com/doc/guides/ruby#Geo-Search)
|
163
|
+
* [Security](http://www.algolia.com/doc/guides/ruby#Security)
|
137
164
|
* [REST API](http://www.algolia.com/doc/rest)
|
138
165
|
|
139
166
|
|
167
|
+
Tutorials
|
168
|
+
================
|
169
|
+
|
170
|
+
Check our [tutorials](http://www.algolia.com/doc/tutorials):
|
171
|
+
* [Searchbar with auto-completion](http://www.algolia.com/doc/tutorials/auto-complete)
|
172
|
+
* [Searchbar with multi-categories auto-completion](http://www.algolia.com/doc/tutorials/multi-auto-complete)
|
173
|
+
* [Instant-search](http://www.algolia.com/doc/tutorials/instant-search)
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
Commands reference
|
178
|
+
==================
|
140
179
|
|
141
180
|
|
142
181
|
|
@@ -197,7 +236,11 @@ index.partial_update_object({"city" => "San Francisco",
|
|
197
236
|
|
198
237
|
Search
|
199
238
|
-------------
|
200
|
-
|
239
|
+
|
240
|
+
**Opening note:** If you are building a web application, you may be more interested in using our [javascript client](https://github.com/algolia/algoliasearch-client-js) to send queries. It brings two benefits:
|
241
|
+
* your users get a better response time by avoiding to go through your servers,
|
242
|
+
* and it will offload your servers of unnecessary tasks.
|
243
|
+
|
201
244
|
|
202
245
|
To perform a search, you just need to initialize the index and perform a call to the search function.
|
203
246
|
|
@@ -212,10 +255,15 @@ You can use the following optional arguments:
|
|
212
255
|
* **prefixAll**: all query words are interpreted as prefixes,
|
213
256
|
* **prefixLast**: only the last word is interpreted as a prefix (default behavior),
|
214
257
|
* **prefixNone**: no query word is interpreted as a prefix. This option is not recommended.
|
258
|
+
* **removeWordsIfNoResult**: This option to select a strategy to avoid having an empty result page. There is three different option:
|
259
|
+
* **LastWords**: when a query does not return any result, the final word will be removed until there is results,
|
260
|
+
* **FirstWords**: when a query does not return any result, the first word will be removed until there is results,
|
261
|
+
* **None**: No specific processing is done when a query does not return any result (default behavior).
|
215
262
|
* **typoTolerance**: if set to false, disable the typo-tolerance. Defaults to true.
|
216
263
|
* **minWordSizefor1Typo**: the minimum number of characters in a query word to accept one typo in this word.<br/>Defaults to 3.
|
217
264
|
* **minWordSizefor2Typos**: the minimum number of characters in a query word to accept two typos in this word.<br/>Defaults to 7.
|
218
265
|
* **allowTyposOnNumericTokens**: if set to false, disable typo-tolerance on numeric tokens (numbers). Default to true.
|
266
|
+
* **restrictSearchableAttributes** List of attributes you want to use for textual search (must be a subset of the `attributesToIndex` index setting). Attributes are separated with a comma (for example `"name,address"`), you can also use a JSON string array encoding (for example encodeURIComponent("[\"name\",\"address\"]")). By default, all attributes specified in `attributesToIndex` settings are used to search.
|
219
267
|
* **advancedSyntax**: Enable the advanced query syntax. Defaults to 0 (false).
|
220
268
|
* **Phrase query**: a phrase query defines a particular sequence of terms. A phrase query is build by Algolia's query parser for words surrounded by `"`. For example, `"search engine"` will retrieve records having `search` next to `engine` only. Typo-tolerance is _disabled_ on phrase queries.
|
221
269
|
* **Prohibit operator**: The prohibit operator excludes records that contain the term after the `-` symbol. For example `search -engine` will retrieve records containing `search` but not `engine`.
|
@@ -232,6 +280,10 @@ You can use the following optional arguments:
|
|
232
280
|
#### Geo-search parameters
|
233
281
|
|
234
282
|
* **aroundLatLng**: search for entries around a given latitude/longitude (specified as two floats separated by a comma).<br/>For example `aroundLatLng=47.316669,5.016670`).<br/>You can specify the maximum distance in meters with the **aroundRadius** parameter (in meters) and the precision for ranking with **aroundPrecision** (for example if you set aroundPrecision=100, two objects that are distant of less than 100m will be considered as identical for "geo" ranking parameter).<br/>At indexing, you should specify geoloc of an object with the `_geoloc` attribute (in the form `{"_geoloc":{"lat":48.853409, "lng":2.348800}}`)
|
283
|
+
|
284
|
+
* **aroundLatLngViaIP**: search for entries around a given latitude/longitude (automatically computed from user IP address).<br/>For example `aroundLatLng=47.316669,5.016670`).<br/>You can specify the maximum distance in meters with the **aroundRadius** parameter (in meters) and the precision for ranking with **aroundPrecision** (for example if you set aroundPrecision=100, two objects that are distant of less than 100m will be considered as identical for "geo" ranking parameter).<br/>At indexing, you should specify geoloc of an object with the `_geoloc` attribute (in the form `{"_geoloc":{"lat":48.853409, "lng":2.348800}}`)
|
285
|
+
|
286
|
+
|
235
287
|
* **insideBoundingBox**: search entries inside a given area defined by the two extreme points of a rectangle (defined by 4 floats: p1Lat,p1Lng,p2Lat,p2Lng).<br/>For example `insideBoundingBox=47.3165,4.9665,47.3424,5.0201`).<br/>At indexing, you should specify geoloc of an object with the _geoloc attribute (in the form `{"_geoloc":{"lat":48.853409, "lng":2.348800}}`)
|
236
288
|
|
237
289
|
#### Parameters to control results content
|
@@ -246,7 +298,7 @@ You can use the following optional arguments:
|
|
246
298
|
|
247
299
|
|
248
300
|
#### Numeric search parameters
|
249
|
-
* **numericFilters**: a string that contains the list of numeric filters you want to apply separated by a comma. The syntax of one filter is `attributeName` followed by `operand` followed by `value`. Supported operands are `<`, `<=`, `=`, `>` and `>=`.
|
301
|
+
* **numericFilters**: a string that contains the list of numeric filters you want to apply separated by a comma. The syntax of one filter is `attributeName` followed by `operand` followed by `value`. Supported operands are `<`, `<=`, `=`, `>` and `>=`.
|
250
302
|
|
251
303
|
You can easily perform range queries via the `:` operator (equivalent to combining a `>=` and `<=` operand), for example `numericFilters=price:10 to 1000`.
|
252
304
|
|
@@ -255,7 +307,7 @@ You can also mix OR and AND operators. The OR operator is defined with a parenth
|
|
255
307
|
You can also use a string array encoding (for example `numericFilters: ["price>100","price<1000"]`).
|
256
308
|
|
257
309
|
#### Category search parameters
|
258
|
-
* **tagFilters**: filter the query by a set of tags. You can AND tags by separating them by commas. To OR tags, you must add parentheses. For example, `tags=tag1,(tag2,tag3)` means *tag1 AND (tag2 OR tag3)*. You can also use a string array encoding, for example `tagFilters: ["tag1",["tag2","tag3"]]` means *tag1 AND (tag2 OR tag3)*.<br/>At indexing, tags should be added in the **_tags** attribute of objects (for example `{"_tags":["tag1","tag2"]}`).
|
310
|
+
* **tagFilters**: filter the query by a set of tags. You can AND tags by separating them by commas. To OR tags, you must add parentheses. For example, `tags=tag1,(tag2,tag3)` means *tag1 AND (tag2 OR tag3)*. You can also use a string array encoding, for example `tagFilters: ["tag1",["tag2","tag3"]]` means *tag1 AND (tag2 OR tag3)*.<br/>At indexing, tags should be added in the **_tags** attribute of objects (for example `{"_tags":["tag1","tag2"]}`).
|
259
311
|
|
260
312
|
#### Faceting parameters
|
261
313
|
* **facetFilters**: filter the query by a list of facets. Facets are separated by commas and each facet is encoded as `attributeName:value`. To OR facets, you must add parentheses. For example: `facetFilters=(category:Book,category:Movie),author:John%20Doe`. You can also use a string array encoding (for example `[["category:Book","category:Movie"],"author:John%20Doe"]`).
|
@@ -308,6 +360,24 @@ The server response will look like:
|
|
308
360
|
```
|
309
361
|
|
310
362
|
|
363
|
+
Multi-queries
|
364
|
+
--------------
|
365
|
+
|
366
|
+
You can send multiple queries with a single API call using a batch of queries:
|
367
|
+
|
368
|
+
```ruby
|
369
|
+
# perform 3 queries in a single API call:
|
370
|
+
# - 1st query targets index `categories`
|
371
|
+
# - 2nd and 3rd queries target index `products`
|
372
|
+
res = Algolia.multiple_queries([{:index_name => "categories", "query" => my_query_string, "hitsPerPage" => 3}
|
373
|
+
, {:index_name => "products", "query" => my_query_string, "hitsPerPage" => 3, "tagFilters" => "promotion"}
|
374
|
+
, {:index_name => "products", "query" => my_query_string, "hitsPerPage" => 10}])
|
375
|
+
|
376
|
+
puts res["results"]
|
377
|
+
```
|
378
|
+
|
379
|
+
|
380
|
+
|
311
381
|
|
312
382
|
|
313
383
|
|
@@ -325,6 +395,12 @@ res = index.get_object("myID", "firstname,lastname")
|
|
325
395
|
res = index.get_object("myID", "fistname")
|
326
396
|
```
|
327
397
|
|
398
|
+
You can also retrieve a set of objects:
|
399
|
+
|
400
|
+
```ruby
|
401
|
+
res = index.get_objects(["myID", "myID2"])
|
402
|
+
```
|
403
|
+
|
328
404
|
Delete an object
|
329
405
|
-------------
|
330
406
|
|
@@ -334,6 +410,18 @@ You can delete an object using its `objectID`:
|
|
334
410
|
index.delete_object("myID")
|
335
411
|
```
|
336
412
|
|
413
|
+
|
414
|
+
Delete by query
|
415
|
+
-------------
|
416
|
+
|
417
|
+
You can delete all objects matching a single query with the following code. Internally, the API client performs the query, delete all matching hits, wait until the deletions have been applied and so on.
|
418
|
+
|
419
|
+
```ruby
|
420
|
+
params = {}
|
421
|
+
index.delete_by_query("John", params)
|
422
|
+
```
|
423
|
+
|
424
|
+
|
337
425
|
Index Settings
|
338
426
|
-------------
|
339
427
|
|
@@ -344,27 +432,29 @@ You can retrieve all settings using the `get_settings` function. The result will
|
|
344
432
|
* **attributesToIndex**: (array of strings) the list of fields you want to index.<br/>If set to null, all textual and numerical attributes of your objects are indexed, but you should update it to get optimal results.<br/>This parameter has two important uses:
|
345
433
|
* *Limit the attributes to index*.<br/>For example if you store a binary image in base64, you want to store it and be able to retrieve it but you don't want to search in the base64 string.
|
346
434
|
* *Control part of the ranking*.<br/>(see the ranking parameter for full explanation) Matches in attributes at the beginning of the list will be considered more important than matches in attributes further down the list. In one attribute, matching text at the beginning of the attribute will be considered more important than text after, you can disable this behavior if you add your attribute inside `unordered(AttributeName)`, for example `attributesToIndex: ["title", "unordered(text)"]`.
|
435
|
+
**Notes**: All numerical attributes are automatically indexed as numerical filters. If you don't need filtering on some of your numerical attributes, please consider sending them as strings to speed up the indexing.<br/>
|
436
|
+
You can decide to have the same priority for two attributes by passing them in the same string using comma as separator. For example `title` and `alternative_title` have the same priority in this example, which is different than text priority: `attributesToIndex:["title,alternative_title", "text"]`
|
347
437
|
* **attributesForFaceting**: (array of strings) The list of fields you want to use for faceting. All strings in the attribute selected for faceting are extracted and added as a facet. If set to null, no attribute is used for faceting.
|
348
438
|
* **attributeForDistinct**: The attribute name used for the `Distinct` feature. This feature is similar to the SQL "distinct" keyword: when enabled in query with the `distinct=1` parameter, all hits containing a duplicate value for this attribute are removed from results. For example, if the chosen attribute is `show_name` and several hits have the same value for `show_name`, then only the best one is kept and others are removed. **Note**: This feature is disabled if the query string is empty and there isn't any `tagFilters`, nor any `facetFilters`, nor any `numericFilters` parameters.
|
349
|
-
* **ranking**: (array of strings) controls the way results are sorted.<br/>We have nine available criteria:
|
439
|
+
* **ranking**: (array of strings) controls the way results are sorted.<br/>We have nine available criteria:
|
350
440
|
* **typo**: sort according to number of typos,
|
351
441
|
* **geo**: sort according to decreassing distance when performing a geo-location based search,
|
352
442
|
* **words**: sort according to the number of query words matched by decreasing order. This parameter is useful when you use `optionalWords` query parameter to have results with the most matched words first.
|
353
443
|
* **proximity**: sort according to the proximity of query words in hits,
|
354
444
|
* **attribute**: sort according to the order of attributes defined by attributesToIndex,
|
355
|
-
* **exact**:
|
445
|
+
* **exact**:
|
356
446
|
* if the user query contains one word: sort objects having an attribute that is exactly the query word before others. For example if you search for the "V" TV show, you want to find it with the "V" query and avoid to have all popular TV show starting by the v letter before it.
|
357
447
|
* if the user query contains multiple words: sort according to the number of words that matched exactly (and not as a prefix).
|
358
448
|
* **custom**: sort according to a user defined formula set in **customRanking** attribute.
|
359
449
|
* **asc(attributeName)**: sort according to a numeric attribute by ascending order. **attributeName** can be the name of any numeric attribute of your records (integer, a double or boolean).
|
360
450
|
* **desc(attributeName)**: sort according to a numeric attribute by descending order. **attributeName** can be the name of any numeric attribute of your records (integer, a double or boolean). <br/>The standard order is ["typo", "geo", "words", "proximity", "attribute", "exact", "custom"]
|
361
451
|
* **customRanking**: (array of strings) lets you specify part of the ranking.<br/>The syntax of this condition is an array of strings containing attributes prefixed by asc (ascending order) or desc (descending order) operator.
|
362
|
-
For example `"customRanking" => ["desc(population)", "asc(name)"]`
|
452
|
+
For example `"customRanking" => ["desc(population)", "asc(name)"]`
|
363
453
|
* **queryType**: Select how the query words are interpreted, it can be one of the following value:
|
364
454
|
* **prefixAll**: all query words are interpreted as prefixes,
|
365
455
|
* **prefixLast**: only the last word is interpreted as a prefix (default behavior),
|
366
456
|
* **prefixNone**: no query word is interpreted as a prefix. This option is not recommended.
|
367
|
-
* **slaves**: The list of
|
457
|
+
* **slaves**: The list of indices on which you want to replicate all write operations. In order to get response times in milliseconds, we pre-compute part of the ranking during indexing. If you want to use different ranking configurations depending of the use-case, you need to create one index per ranking configuration. This option enables you to perform write operations only on this index, and to automatically update slave indices with the same operations.
|
368
458
|
|
369
459
|
#### Query expansion
|
370
460
|
* **synonyms**: (array of array of words considered as equals). For example, you may want to retrieve your **black ipad** record when your users are searching for **dark ipad**, even if the **dark** word is not part of the record: so you need to configure **black** as a synonym of **dark**. For example `"synomyms": [ [ "black", "dark" ], [ "small", "little", "mini" ], ... ]`.
|
@@ -401,9 +491,9 @@ puts settings.to_json
|
|
401
491
|
index.set_settings({"customRanking" => ["desc(followers)"]})
|
402
492
|
```
|
403
493
|
|
404
|
-
List
|
494
|
+
List indices
|
405
495
|
-------------
|
406
|
-
You can list all your
|
496
|
+
You can list all your indices with their associated information (number of entries, disk size, etc.) with the `list_indexes` method:
|
407
497
|
|
408
498
|
```ruby
|
409
499
|
Algolia.list_indexes
|
@@ -429,7 +519,7 @@ index.clear_index
|
|
429
519
|
Wait indexing
|
430
520
|
-------------
|
431
521
|
|
432
|
-
All write operations return a `taskID` when the job is securely stored on our infrastructure but not when the job is published in your index. Even if it's extremely fast, you can easily ensure indexing is complete using the same method with a `!`.
|
522
|
+
All write operations return a `taskID` when the job is securely stored on our infrastructure but not when the job is published in your index. Even if it's extremely fast, you can easily ensure indexing is complete using the same method with a `!`.
|
433
523
|
|
434
524
|
For example, to wait for indexing of a new object:
|
435
525
|
```ruby
|
@@ -486,8 +576,8 @@ res = index.partial_update_objects([{"firstname" => "Jimmie",
|
|
486
576
|
Security / User API Keys
|
487
577
|
-------------
|
488
578
|
|
489
|
-
The admin API key provides full control of all your
|
490
|
-
You can also generate user API keys to control security.
|
579
|
+
The admin API key provides full control of all your indices.
|
580
|
+
You can also generate user API keys to control security.
|
491
581
|
These API keys can be restricted to a set of operations or/and restricted to a given index.
|
492
582
|
|
493
583
|
To list existing keys, you can use `list_user_keys` method:
|
@@ -526,7 +616,7 @@ You can also create an API Key with advanced restrictions:
|
|
526
616
|
Note: If you are sending the query through your servers, you must use the `Algolia.with_rate_limits("EndUserIP", "APIKeyWithRateLimit") do ... end` block to enable rate-limit.
|
527
617
|
|
528
618
|
* Specify the maximum number of hits this API key can retrieve in one call. Defaults to 0 (unlimited). This parameter can be used to protect you from attempts at retrieving your entire content by massively querying the index.
|
529
|
-
* Specify the list of targeted
|
619
|
+
* Specify the list of targeted indices, you can target all indices starting by a prefix or finishing by a suffix with the '*' character (for example "dev_*" matches all indices starting by "dev_" and "*_dev" matches all indices finishing by "_dev"). Defaults to all indices if empty of blank.
|
530
620
|
|
531
621
|
```ruby
|
532
622
|
# Creates a new global API key that is valid for 300 seconds
|
@@ -629,7 +719,7 @@ puts Algolia.move_index("MyNewIndex", "MyIndex")
|
|
629
719
|
Backup / Retrieve all index content
|
630
720
|
-------------
|
631
721
|
|
632
|
-
You can retrieve all index content for backup purpose or for analytics using the browse method.
|
722
|
+
You can retrieve all index content for backup purpose or for analytics using the browse method.
|
633
723
|
This method retrieve 1000 objects by API call and support pagination.
|
634
724
|
|
635
725
|
```ruby
|
@@ -642,7 +732,7 @@ puts index.browse(1)
|
|
642
732
|
Logs
|
643
733
|
-------------
|
644
734
|
|
645
|
-
You can retrieve the last logs via this API. Each log entry contains:
|
735
|
+
You can retrieve the last logs via this API. Each log entry contains:
|
646
736
|
* Timestamp in ISO-8601 format
|
647
737
|
* Client IP
|
648
738
|
* Request Headers (API-Key is obfuscated)
|
data/algoliasearch.gemspec
CHANGED
@@ -6,12 +6,12 @@
|
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "algoliasearch"
|
9
|
-
s.version = "1.2.
|
9
|
+
s.version = "1.2.10"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Algolia"]
|
14
|
-
s.date = "2014-
|
14
|
+
s.date = "2014-08-22"
|
15
15
|
s.description = "A simple Ruby client for the algolia.com REST API"
|
16
16
|
s.email = "contact@algolia.com"
|
17
17
|
s.extra_rdoc_files = [
|
data/lib/algolia/client.rb
CHANGED
@@ -10,7 +10,7 @@ module Algolia
|
|
10
10
|
# A class which encapsulates the HTTPS communication with the Algolia
|
11
11
|
# API server. Uses the HTTPClient library for low-level HTTP communication.
|
12
12
|
class Client
|
13
|
-
attr_reader :ssl, :hosts, :application_id, :api_key, :headers, :connect_timeout, :send_timeout, :receive_timeout
|
13
|
+
attr_reader :ssl, :hosts, :application_id, :api_key, :headers, :connect_timeout, :send_timeout, :receive_timeout, :search_timeout
|
14
14
|
|
15
15
|
|
16
16
|
def initialize(data = {})
|
@@ -21,6 +21,7 @@ module Algolia
|
|
21
21
|
@connect_timeout = data[:connect_timeout]
|
22
22
|
@send_timeout = data[:send_timeout]
|
23
23
|
@receive_timeout = data[:receive_timeout]
|
24
|
+
@search_timeout = data[:search_timeout]
|
24
25
|
@headers = {
|
25
26
|
Protocol::HEADER_API_KEY => api_key,
|
26
27
|
Protocol::HEADER_APP_ID => application_id,
|
@@ -33,11 +34,11 @@ module Algolia
|
|
33
34
|
# with common basic response handling. Will raise a
|
34
35
|
# AlgoliaProtocolError if the response has an error status code,
|
35
36
|
# and will return the parsed JSON body on success, if there is one.
|
36
|
-
def request(uri, method, data = nil)
|
37
|
+
def request(uri, method, data = nil, timeout = nil)
|
37
38
|
exceptions = []
|
38
39
|
thread_local_hosts.each do |host|
|
39
40
|
begin
|
40
|
-
return perform_request(host[:session], host[:base_url] + uri, method, data)
|
41
|
+
return perform_request(host[:session], host[:base_url] + uri, method, data, timeout)
|
41
42
|
rescue AlgoliaProtocolError => e
|
42
43
|
raise if e.code != Protocol::ERROR_TIMEOUT and e.code != Protocol::ERROR_UNAVAILABLE
|
43
44
|
exceptions << e
|
@@ -48,19 +49,19 @@ module Algolia
|
|
48
49
|
raise AlgoliaProtocolError.new(0, "Cannot reach any host: #{exceptions.map { |e| e.to_s }.join(', ')}")
|
49
50
|
end
|
50
51
|
|
51
|
-
def get(uri)
|
52
|
-
request(uri, :GET)
|
52
|
+
def get(uri, timeout = nil)
|
53
|
+
request(uri, :GET, nil, timeout)
|
53
54
|
end
|
54
55
|
|
55
|
-
def post(uri, body = {})
|
56
|
-
request(uri, :POST, body)
|
56
|
+
def post(uri, body = {}, timeout = nil)
|
57
|
+
request(uri, :POST, body, timeout)
|
57
58
|
end
|
58
59
|
|
59
|
-
def put(uri, body = {})
|
60
|
+
def put(uri, body = {}, timeout = nil)
|
60
61
|
request(uri, :PUT, body)
|
61
62
|
end
|
62
63
|
|
63
|
-
def delete(uri)
|
64
|
+
def delete(uri, timeout = nil)
|
64
65
|
request(uri, :DELETE)
|
65
66
|
end
|
66
67
|
|
@@ -83,21 +84,29 @@ module Algolia
|
|
83
84
|
end
|
84
85
|
|
85
86
|
private
|
86
|
-
def perform_request(session, url, method, data)
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
87
|
+
def perform_request(session, url, method, data, timeout)
|
88
|
+
original_send_timeout = session.send_timeout
|
89
|
+
original_receive_timeout = session.receive_timeout
|
90
|
+
begin
|
91
|
+
session.send_timeout = session.receive_timeout = timeout if timeout
|
92
|
+
response = case method
|
93
|
+
when :GET
|
94
|
+
session.get(url, { :header => @headers })
|
95
|
+
when :POST
|
96
|
+
session.post(url, { :body => data, :header => @headers })
|
97
|
+
when :PUT
|
98
|
+
session.put(url, { :body => data, :header => @headers })
|
99
|
+
when :DELETE
|
100
|
+
session.delete(url, { :header => @headers })
|
101
|
+
end
|
102
|
+
if response.code >= 400 || response.code < 200
|
103
|
+
raise AlgoliaProtocolError.new(response.code, "Cannot #{method} to #{url}: #{response.content} (#{response.code})")
|
104
|
+
end
|
105
|
+
return JSON.parse(response.content)
|
106
|
+
ensure
|
107
|
+
session.send_timeout = original_send_timeout
|
108
|
+
session.receive_timeout = original_receive_timeout
|
99
109
|
end
|
100
|
-
return JSON.parse(response.content)
|
101
110
|
end
|
102
111
|
|
103
112
|
end
|
@@ -170,7 +179,7 @@ module Algolia
|
|
170
179
|
tag_filters = tag_filters.map { |t| t.is_a?(Array) ? "(#{t.join(',')})" : t }.join(',')
|
171
180
|
end
|
172
181
|
raise ArgumentError.new('Attribute "tag_filters" must be a list of tags') if !tag_filters.is_a?(String)
|
173
|
-
OpenSSL::HMAC.hexdigest(OpenSSL::Digest
|
182
|
+
OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), private_api_key, "#{tag_filters}#{user_token.to_s}")
|
174
183
|
end
|
175
184
|
|
176
185
|
#
|
@@ -187,7 +196,7 @@ module Algolia
|
|
187
196
|
{ :indexName => indexName, :params => Protocol.to_query(encoded_params) }
|
188
197
|
end
|
189
198
|
}
|
190
|
-
Algolia.client.post(Protocol.multiple_queries_uri, requests.to_json)
|
199
|
+
Algolia.client.post(Protocol.multiple_queries_uri, requests.to_json, Algolia.client.search_timeout)
|
191
200
|
end
|
192
201
|
|
193
202
|
#
|
data/lib/algolia/index.rb
CHANGED
@@ -136,7 +136,7 @@ module Algolia
|
|
136
136
|
# one is kept and others are removed.
|
137
137
|
def search(query, params = {})
|
138
138
|
encoded_params = Hash[params.map { |k,v| [k.to_s, v.is_a?(Array) ? v.to_json : v] }]
|
139
|
-
Algolia.client.get(Protocol.search_uri(name, query, encoded_params))
|
139
|
+
Algolia.client.get(Protocol.search_uri(name, query, encoded_params), Algolia.client.search_timeout)
|
140
140
|
end
|
141
141
|
|
142
142
|
#
|
data/lib/algolia/version.rb
CHANGED
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.2.
|
4
|
+
version: 1.2.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Algolia
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-22 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.
|
134
|
+
rubygems_version: 2.2.2
|
135
135
|
signing_key:
|
136
136
|
specification_version: 4
|
137
137
|
summary: A simple Ruby client for the algolia.com REST API
|