algoliasearch 1.12.6 → 1.12.7
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 +33 -2770
- data/lib/algolia/client.rb +41 -10
- data/lib/algolia/index.rb +12 -5
- data/lib/algolia/version.rb +1 -1
- data/spec/client_spec.rb +24 -24
- data/spec/mock_spec.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: 3c2db1d4cb3dd9d598ae67374ce047c0537cc336
|
4
|
+
data.tar.gz: 26b61accfebfad33730f6bc9f37aa9df1b8812f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7041be1e54b500f18993340631e1016ac296442cd428528b8568ad416b86e1321babda347cc4455f05fa965436b2e4fdd136abb146becd531db2d620daefdd7b
|
7
|
+
data.tar.gz: 819a1b0c3f5b17ba9cabcf9ac6fc2c87e143cc6f6737232eda60ad687ed4908aee60192f4a3e7a4526c15d96c447829a17893d5d2356865ab3c4c915b39074ca
|
data/ChangeLog
CHANGED
data/README.md
CHANGED
@@ -6,114 +6,35 @@ The **Algolia Search API Client for Ruby** lets you easily use the [Algolia Sear
|
|
6
6
|
[![Build Status](https://travis-ci.org/algolia/algoliasearch-client-ruby.svg?branch=master)](https://travis-ci.org/algolia/algoliasearch-client-ruby) [![Gem Version](https://badge.fury.io/rb/algoliasearch.svg)](http://badge.fury.io/rb/algoliasearch) [![Code Climate](https://codeclimate.com/github/algolia/algoliasearch-client-ruby.svg)](https://codeclimate.com/github/algolia/algoliasearch-client-ruby) [![Coverage Status](https://coveralls.io/repos/algolia/algoliasearch-client-ruby/badge.svg)](https://coveralls.io/r/algolia/algoliasearch-client-ruby)
|
7
7
|
|
8
8
|
|
9
|
-
**
|
10
|
-
[Algolia's website](https://www.algolia.com/doc/api-client/ruby/).
|
9
|
+
If you are a **Ruby on Rails** user, you are probably looking for the [algoliasearch-rails](https://github.com/algolia/algoliasearch-rails) gem.
|
11
10
|
|
12
|
-
# Table of Contents
|
13
11
|
|
14
12
|
|
15
|
-
**Getting Started**
|
16
13
|
|
17
|
-
|
18
|
-
1. [Init index - `init_index`](#init-index---initindex)
|
19
|
-
1. [Quick Start](#quick-start)
|
14
|
+
## API Documentation
|
20
15
|
|
21
|
-
|
16
|
+
You can find the full reference on [Algolia's website](https://www.algolia.com/doc/api-client/ruby/).
|
22
17
|
|
23
|
-
1. [Search an index - `search`](#search-an-index---search)
|
24
|
-
1. [Search Response Format](#search-response-format)
|
25
|
-
1. [Search Parameters](#search-parameters)
|
26
|
-
1. [Search multiple indices - `multiple_queries`](#search-multiple-indices---multiplequeries)
|
27
|
-
1. [Get Objects - `get_objects`](#get-objects---getobjects)
|
28
|
-
1. [Search for facet values - `search_for_facet_values`](#search-for-facet-values---searchforfacetvalues)
|
29
18
|
|
30
|
-
|
19
|
+
## Table of Contents
|
31
20
|
|
32
|
-
1. [Add Objects - `add_objects`](#add-objects---addobjects)
|
33
|
-
1. [Update objects - `save_objects`](#update-objects---saveobjects)
|
34
|
-
1. [Partial update objects - `partial_update_objects`](#partial-update-objects---partialupdateobjects)
|
35
|
-
1. [Delete objects - `delete_objects`](#delete-objects---deleteobjects)
|
36
|
-
1. [Delete by query - `delete_by_query`](#delete-by-query---deletebyquery)
|
37
|
-
1. [Wait for operations - `wait_task`](#wait-for-operations---waittask)
|
38
21
|
|
39
|
-
**
|
22
|
+
1. **[Install](#install)**
|
40
23
|
|
41
|
-
|
42
|
-
1. [Set settings - `set_settings`](#set-settings---setsettings)
|
43
|
-
1. [Index settings parameters](#index-settings-parameters)
|
24
|
+
* [Ruby on Rails](#ruby-on-rails)
|
44
25
|
|
45
|
-
**
|
26
|
+
1. **[Quick Start](#quick-start)**
|
46
27
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
1. [Highlighting / Snippeting](#highlighting--snippeting)
|
53
|
-
1. [Pagination](#pagination)
|
54
|
-
1. [Typos](#typos)
|
55
|
-
1. [Geo-Search](#geo-search)
|
56
|
-
1. [Query Strategy](#query-strategy)
|
57
|
-
1. [Performance](#performance)
|
58
|
-
1. [Advanced](#advanced)
|
28
|
+
* [Initialize the client](#initialize-the-client)
|
29
|
+
* [Push data](#push-data)
|
30
|
+
* [Search](#search)
|
31
|
+
* [Configure](#configure)
|
32
|
+
* [Frontend search](#frontend-search)
|
59
33
|
|
60
|
-
**
|
34
|
+
1. **[Getting Help](#getting-help)**
|
61
35
|
|
62
|
-
1. [Create an index](#create-an-index)
|
63
|
-
1. [List indices - `list_indexes`](#list-indices---listindexes)
|
64
|
-
1. [Delete an index - `delete_index`](#delete-an-index---deleteindex)
|
65
|
-
1. [Clear an index - `clear_index`](#clear-an-index---clearindex)
|
66
|
-
1. [Copy index - `copy_index`](#copy-index---copyindex)
|
67
|
-
1. [Move index - `move_index`](#move-index---moveindex)
|
68
36
|
|
69
|
-
**Api keys**
|
70
37
|
|
71
|
-
1. [Overview](#overview)
|
72
|
-
1. [Generate key - `generate_secured_api_key`](#generate-key---generatesecuredapikey)
|
73
|
-
|
74
|
-
**Synonyms**
|
75
|
-
|
76
|
-
1. [Save synonym - `save_synonym`](#save-synonym---savesynonym)
|
77
|
-
1. [Batch synonyms - `batch_synonyms`](#batch-synonyms---batchsynonyms)
|
78
|
-
1. [Editing Synonyms](#editing-synonyms)
|
79
|
-
1. [Delete synonym - `delete_synonym`](#delete-synonym---deletesynonym)
|
80
|
-
1. [Clear all synonyms - `clear_synonyms`](#clear-all-synonyms---clearsynonyms)
|
81
|
-
1. [Get synonym - `get_synonym`](#get-synonym---getsynonym)
|
82
|
-
1. [Search synonyms - `search_synonyms`](#search-synonyms---searchsynonyms)
|
83
|
-
|
84
|
-
**Advanced**
|
85
|
-
|
86
|
-
1. [Custom batch - `batch`](#custom-batch---batch)
|
87
|
-
1. [Backup / Export an index - `browse`](#backup--export-an-index---browse)
|
88
|
-
1. [List api keys - `list_api_keys`](#list-api-keys---listapikeys)
|
89
|
-
1. [Add user key - `add_user_key`](#add-user-key---adduserkey)
|
90
|
-
1. [Update user key - `update_user_key`](#update-user-key---updateuserkey)
|
91
|
-
1. [Delete user key - `delete_user_key`](#delete-user-key---deleteuserkey)
|
92
|
-
1. [Get key permissions - `get_user_key_acl`](#get-key-permissions---getuserkeyacl)
|
93
|
-
1. [Get latest logs - `get_logs`](#get-latest-logs---getlogs)
|
94
|
-
1. [REST API](#rest-api)
|
95
|
-
|
96
|
-
**Mocking**
|
97
|
-
|
98
|
-
1. [Webmock](#webmock)
|
99
|
-
|
100
|
-
|
101
|
-
# Guides & Tutorials
|
102
|
-
|
103
|
-
Check our [online guides](https://www.algolia.com/doc):
|
104
|
-
|
105
|
-
* [Data Formatting](https://www.algolia.com/doc/indexing/formatting-your-data)
|
106
|
-
* [Import and Synchronize data](https://www.algolia.com/doc/indexing/import-synchronize-data/php)
|
107
|
-
* [Autocomplete](https://www.algolia.com/doc/search/auto-complete)
|
108
|
-
* [Instant search page](https://www.algolia.com/doc/search/instant-search)
|
109
|
-
* [Filtering and Faceting](https://www.algolia.com/doc/search/filtering-faceting)
|
110
|
-
* [Sorting](https://www.algolia.com/doc/relevance/sorting)
|
111
|
-
* [Ranking Formula](https://www.algolia.com/doc/relevance/ranking)
|
112
|
-
* [Typo-Tolerance](https://www.algolia.com/doc/relevance/typo-tolerance)
|
113
|
-
* [Geo-Search](https://www.algolia.com/doc/geo-search/geo-search-overview)
|
114
|
-
* [Security](https://www.algolia.com/doc/security/best-security-practices)
|
115
|
-
* [API-Keys](https://www.algolia.com/doc/security/api-keys)
|
116
|
-
* [REST API](https://www.algolia.com/doc/rest)
|
117
38
|
|
118
39
|
|
119
40
|
# Getting Started
|
@@ -132,9 +53,14 @@ gem install algoliasearch
|
|
132
53
|
|
133
54
|
If you're a Ruby on Rails user; you're probably looking for the [algoliasearch-rails](https://github.com/algolia/algoliasearch-rails) gem.
|
134
55
|
|
135
|
-
##
|
56
|
+
## Quick Start
|
57
|
+
|
58
|
+
In 30 seconds, this quick start tutorial will show you how to index and search objects.
|
59
|
+
|
60
|
+
### Initialize the client
|
136
61
|
|
137
|
-
|
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).
|
138
64
|
|
139
65
|
```ruby
|
140
66
|
require 'rubygems'
|
@@ -144,9 +70,7 @@ Algolia.init :application_id => "YourApplicationID",
|
|
144
70
|
:api_key => "YourAPIKey"
|
145
71
|
```
|
146
72
|
|
147
|
-
|
148
|
-
|
149
|
-
In 30 seconds, this quick start tutorial will show you how to index and search objects.
|
73
|
+
### Push data
|
150
74
|
|
151
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:
|
152
76
|
```ruby
|
@@ -155,6 +79,8 @@ batch = JSON.parse(File.read("contacts.json"))
|
|
155
79
|
index.add_objects(batch)
|
156
80
|
```
|
157
81
|
|
82
|
+
### Search
|
83
|
+
|
158
84
|
You can now search for contacts using firstname, lastname, company, etc. (even with typos):
|
159
85
|
|
160
86
|
```ruby
|
@@ -168,6 +94,8 @@ puts index.search('california paint').to_json
|
|
168
94
|
puts index.search('jimmie paint').to_json
|
169
95
|
```
|
170
96
|
|
97
|
+
### Configure
|
98
|
+
|
171
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:
|
172
100
|
|
173
101
|
```ruby
|
@@ -176,19 +104,17 @@ index.set_settings({"customRanking" => ["desc(followers)"]})
|
|
176
104
|
|
177
105
|
You can also configure the list of attributes you want to index by order of importance (first = most important):
|
178
106
|
|
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:
|
109
|
+
|
179
110
|
```ruby
|
180
111
|
index.set_settings({"searchableAttributes" => ["lastname", "firstname", "company",
|
181
112
|
"email", "city", "address"]})
|
182
113
|
```
|
183
114
|
|
184
|
-
|
115
|
+
### Frontend search
|
185
116
|
|
186
|
-
|
187
|
-
puts index.search('or').to_json
|
188
|
-
puts index.search('jim').to_json
|
189
|
-
```
|
190
|
-
|
191
|
-
**Note:** **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.
|
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.
|
192
118
|
|
193
119
|
It brings two benefits:
|
194
120
|
* Your users get a better response time by not going through your servers
|
@@ -224,2673 +150,10 @@ function searchCallback(err, content) {
|
|
224
150
|
</script>
|
225
151
|
```
|
226
152
|
|
153
|
+
## Getting Help
|
227
154
|
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
## Search an index - `search`
|
233
|
-
|
234
|
-
**Notes:** 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. It brings two benefits:
|
235
|
-
* Your users get a better response time by not going through your servers
|
236
|
-
* It will offload unnecessary tasks from your servers.
|
237
|
-
|
238
|
-
To perform a search, you only need to initialize the index and perform a call to the search function.
|
239
|
-
|
240
|
-
The search query allows only to retrieve 1000 hits. If you need to retrieve more than 1000 hits (e.g. for SEO), you can use [Backup / Export an index](#backup--export-an-index).
|
241
|
-
|
242
|
-
```ruby
|
243
|
-
index = Algolia::Index.new("contacts")
|
244
|
-
res = index.search("query string")
|
245
|
-
res = index.search("query string", { "attributesToRetrieve" => "firstname,lastname", "hitsPerPage" => 20})
|
246
|
-
```
|
247
|
-
|
248
|
-
## Search Response Format
|
249
|
-
|
250
|
-
### Sample
|
251
|
-
|
252
|
-
The server response will look like:
|
253
|
-
|
254
|
-
```json
|
255
|
-
{
|
256
|
-
"hits": [
|
257
|
-
{
|
258
|
-
"firstname": "Jimmie",
|
259
|
-
"lastname": "Barninger",
|
260
|
-
"objectID": "433",
|
261
|
-
"_highlightResult": {
|
262
|
-
"firstname": {
|
263
|
-
"value": "<em>Jimmie</em>",
|
264
|
-
"matchLevel": "partial"
|
265
|
-
},
|
266
|
-
"lastname": {
|
267
|
-
"value": "Barninger",
|
268
|
-
"matchLevel": "none"
|
269
|
-
},
|
270
|
-
"company": {
|
271
|
-
"value": "California <em>Paint</em> & Wlpaper Str",
|
272
|
-
"matchLevel": "partial"
|
273
|
-
}
|
274
|
-
}
|
275
|
-
}
|
276
|
-
],
|
277
|
-
"page": 0,
|
278
|
-
"nbHits": 1,
|
279
|
-
"nbPages": 1,
|
280
|
-
"hitsPerPage": 20,
|
281
|
-
"processingTimeMS": 1,
|
282
|
-
"query": "jimmie paint",
|
283
|
-
"params": "query=jimmie+paint&attributesToRetrieve=firstname,lastname&hitsPerPage=50"
|
284
|
-
}
|
285
|
-
```
|
286
|
-
|
287
|
-
### Fields
|
288
|
-
|
289
|
-
- `hits` (array): The hits returned by the search, sorted according to the ranking formula.
|
290
|
-
|
291
|
-
Hits are made of the JSON objects that you stored in the index; therefore, they are mostly schema-less. However, Algolia does enrich them with a few additional fields:
|
292
|
-
|
293
|
-
- `_highlightResult` (object, optional): Highlighted attributes. *Note: Only returned when [attributesToHighlight](#attributestohighlight) is non-empty.*
|
294
|
-
|
295
|
-
- `${attribute_name}` (object): Highlighting for one attribute.
|
296
|
-
|
297
|
-
- `value` (string): Markup text with occurrences highlighted. The tags used for highlighting are specified via [highlightPreTag](#highlightpretag) and [highlightPostTag](#highlightposttag).
|
298
|
-
|
299
|
-
- `matchLevel` (string, enum) = {`none` \| `partial` \| `full`}: Indicates how well the attribute matched the search query.
|
300
|
-
|
301
|
-
- `matchedWords` (array): List of words *from the query* that matched the object.
|
302
|
-
|
303
|
-
- `fullyHighlighted` (boolean): Whether the entire attribute value is highlighted.
|
304
|
-
|
305
|
-
- `_snippetResult` (object, optional): Snippeted attributes. *Note: Only returned when [attributesToSnippet](#attributestosnippet) is non-empty.*
|
306
|
-
|
307
|
-
- `${attribute_name}` (object): Snippeting for the corresponding attribute.
|
308
|
-
|
309
|
-
- `value` (string): Markup text with occurrences highlighted and optional ellipsis indicators. The tags used for highlighting are specified via [highlightPreTag](#highlightpretag) and [highlightPostTag](#highlightposttag). The text used to indicate ellipsis is specified via [snippetEllipsisText](#snippetellipsistext).
|
310
|
-
|
311
|
-
- `matchLevel` (string, enum) = {`none` \| `partial` \| `full`}: Indicates how well the attribute matched the search query.
|
312
|
-
|
313
|
-
- `_rankingInfo` (object, optional): Ranking information. *Note: Only returned when [getRankingInfo](#getrankinginfo) is `true`.*
|
314
|
-
|
315
|
-
- `nbTypos` (integer): Number of typos encountered when matching the record. Corresponds to the `typos` ranking criterion in the ranking formula.
|
316
|
-
|
317
|
-
- `firstMatchedWord` (integer): Position of the most important matched attribute in the attributes to index list. Corresponds to the `attribute` ranking criterion in the ranking formula.
|
318
|
-
|
319
|
-
- `proximityDistance` (integer): When the query contains more than one word, the sum of the distances between matched words. Corresponds to the `proximity` criterion in the ranking formula.
|
320
|
-
|
321
|
-
- `userScore` (integer): Custom ranking for the object, expressed as a single numerical value. Conceptually, it's what the position of the object would be in the list of all objects sorted by custom ranking. Corresponds to the `custom` criterion in the ranking formula.
|
322
|
-
|
323
|
-
- `geoDistance` (integer): Distance between the geo location in the search query and the best matching geo location in the record, divided by the geo precision.
|
324
|
-
|
325
|
-
- `geoPrecision` (integer): Precision used when computed the geo distance, in meters. All distances will be floored to a multiple of this precision.
|
326
|
-
|
327
|
-
- `nbExactWords` (integer): Number of exactly matched words. If `alternativeAsExact` is set, it may include plurals and/or synonyms.
|
328
|
-
|
329
|
-
- `words` (integer): Number of matched words, including prefixes and typos.
|
330
|
-
|
331
|
-
- `filters` (integer): *This field is reserved for advanced usage.* It will be zero in most cases.
|
332
|
-
|
333
|
-
- `matchedGeoLocation` (object): Geo location that matched the query. *Note: Only returned for a geo search.*
|
334
|
-
|
335
|
-
- `lat` (float): Latitude of the matched location.
|
336
|
-
|
337
|
-
- `lng` (float): Longitude of the matched location.
|
338
|
-
|
339
|
-
- `distance` (integer): Distance between the matched location and the search location (in meters). **Caution:** Contrary to `geoDistance`, this value is *not* divided by the geo precision.
|
340
|
-
|
341
|
-
- `_distinctSeqID` (integer): *Note: Only returned when [distinct](#distinct) is non-zero.* When two consecutive results have the same value for the attribute used for "distinct", this field is used to distinguish between them.
|
342
|
-
|
343
|
-
- `nbHits` (integer): Number of hits that the search query matched.
|
344
|
-
|
345
|
-
- `page` (integer): Index of the current page (zero-based). See the [page](#page) search parameter. *Note: Not returned if you use `offset`/`length` for pagination.*
|
346
|
-
|
347
|
-
- `hitsPerPage` (integer): Maximum number of hits returned per page. See the [hitsPerPage](#hitsperpage) search parameter. *Note: Not returned if you use `offset`/`length` for pagination.*
|
348
|
-
|
349
|
-
- `nbPages` (integer): Number of pages corresponding to the number of hits. Basically, `ceil(nbHits / hitsPerPage)`. *Note: Not returned if you use `offset`/`length` for pagination.*
|
350
|
-
|
351
|
-
- `processingTimeMS` (integer): Time that the server took to process the request, in milliseconds. *Note: This does not include network time.*
|
352
|
-
|
353
|
-
- `query` (string): An echo of the query text. See the [query](#query) search parameter.
|
354
|
-
|
355
|
-
- `queryAfterRemoval` (string, optional): *Note: Only returned when [removeWordsIfNoResults](#removewordsifnoresults) is set to `lastWords` or `firstWords`.* A markup text indicating which parts of the original query have been removed in order to retrieve a non-empty result set. The removed parts are surrounded by `<em>` tags.
|
356
|
-
|
357
|
-
- `params` (string, URL-encoded): An echo of all search parameters.
|
358
|
-
|
359
|
-
- `message` (string, optional): Used to return warnings about the query.
|
360
|
-
|
361
|
-
- `aroundLatLng` (string, optional): *Note: Only returned when [aroundLatLngViaIP](#aroundlatlngviaip) is set.* The computed geo location. **Warning: for legacy reasons, this parameter is a string and not an object.** Format: `${lat},${lng}`, where the latitude and longitude are expressed as decimal floating point numbers.
|
362
|
-
|
363
|
-
- `automaticRadius` (integer, optional): *Note: Only returned for geo queries without an explicitly specified radius (see `aroundRadius`).* The automatically computed radius. **Warning: for legacy reasons, this parameter is a string and not an integer.**
|
364
|
-
|
365
|
-
When [getRankingInfo](#getrankinginfo) is set to `true`, the following additional fields are returned:
|
366
|
-
|
367
|
-
- `serverUsed` (string): Actual host name of the server that processed the request. (Our DNS supports automatic failover and load balancing, so this may differ from the host name used in the request.)
|
368
|
-
|
369
|
-
- `parsedQuery` (string): The query string that will be searched, after normalization. Normalization includes removing stop words (if [removeStopWords](#removestopwords) is enabled), and transforming portions of the query string into phrase queries (see [advancedSyntax](#advancedsyntax)).
|
370
|
-
|
371
|
-
- `timeoutCounts` (boolean) - DEPRECATED: Please use `exhaustiveFacetsCount` in remplacement.
|
372
|
-
|
373
|
-
- `timeoutHits` (boolean) - DEPRECATED: Please use `exhaustiveFacetsCount` in remplacement.
|
374
|
-
|
375
|
-
... and ranking information is also added to each of the hits (see above).
|
376
|
-
|
377
|
-
When [facets](#facets) is non-empty, the following additional fields are returned:
|
378
|
-
|
379
|
-
- `facets` (object): Maps each facet name to the corresponding facet counts:
|
380
|
-
|
381
|
-
- `${facet_name}` (object): Facet counts for the corresponding facet name:
|
382
|
-
|
383
|
-
- `${facet_value}` (integer): Count for this facet value.
|
384
|
-
|
385
|
-
- `facets_stats` (object, optional): *Note: Only returned when at least one of the returned facets contains numerical values.* Statistics for numerical facets:
|
386
|
-
|
387
|
-
- `${facet_name}` (object): The statistics for a given facet:
|
388
|
-
|
389
|
-
- `min` (integer | float): The minimum value in the result set.
|
390
|
-
|
391
|
-
- `max` (integer | float): The maximum value in the result set.
|
392
|
-
|
393
|
-
- `avg` (integer | float): The average facet value in the result set.
|
394
|
-
|
395
|
-
- `sum` (integer | float): The sum of all values in the result set.
|
396
|
-
|
397
|
-
- `exhaustiveFacetsCount` (boolean): Whether the counts are exhaustive (`true`) or approximate (`false`). *Note: In some conditions when [distinct](#distinct) is greater than 1 and an empty query without refinement is sent, the facet counts may not always be exhaustive.*
|
398
|
-
|
399
|
-
## Search Parameters
|
400
|
-
|
401
|
-
Here is the list of parameters you can use with the search method (`search` [scope](#scope)):
|
402
|
-
Parameters that can also be used in a setSettings also have the `indexing` [scope](#scope)
|
403
|
-
|
404
|
-
**Search**
|
405
|
-
|
406
|
-
- [query](#query) `search`
|
407
|
-
|
408
|
-
**Attributes**
|
409
|
-
|
410
|
-
- [attributesToRetrieve](#attributestoretrieve) `settings`, `search`
|
411
|
-
- [restrictSearchableAttributes](#restrictsearchableattributes) `search`
|
412
|
-
|
413
|
-
**Filtering / Faceting**
|
414
|
-
|
415
|
-
- [filters](#filters) `search`
|
416
|
-
- [facets](#facets) `search`
|
417
|
-
- [maxValuesPerFacet](#maxvaluesperfacet) `settings`, `search`
|
418
|
-
- [facetFilters](#facetfilters) `search`
|
419
|
-
|
420
|
-
**Highlighting / Snippeting**
|
421
|
-
|
422
|
-
- [attributesToHighlight](#attributestohighlight) `settings`, `search`
|
423
|
-
- [attributesToSnippet](#attributestosnippet) `settings`, `search`
|
424
|
-
- [highlightPreTag](#highlightpretag) `settings`, `search`
|
425
|
-
- [highlightPostTag](#highlightposttag) `settings`, `search`
|
426
|
-
- [snippetEllipsisText](#snippetellipsistext) `settings`, `search`
|
427
|
-
- [restrictHighlightAndSnippetArrays](#restricthighlightandsnippetarrays) `settings`, `search`
|
428
|
-
|
429
|
-
**Pagination**
|
430
|
-
|
431
|
-
- [page](#page) `search`
|
432
|
-
- [hitsPerPage](#hitsperpage) `settings`, `search`
|
433
|
-
- [offset](#offset) `search`
|
434
|
-
- [length](#length) `search`
|
435
|
-
|
436
|
-
**Typos**
|
437
|
-
|
438
|
-
- [minWordSizefor1Typo](#minwordsizefor1typo) `settings`, `search`
|
439
|
-
- [minWordSizefor2Typos](#minwordsizefor2typos) `settings`, `search`
|
440
|
-
- [typoTolerance](#typotolerance) `settings`, `search`
|
441
|
-
- [allowTyposOnNumericTokens](#allowtyposonnumerictokens) `settings`, `search`
|
442
|
-
- [ignorePlurals](#ignoreplurals) `settings`, `search`
|
443
|
-
- [disableTypoToleranceOnAttributes](#disabletypotoleranceonattributes) `settings`, `search`
|
444
|
-
|
445
|
-
**Geo-Search**
|
446
|
-
|
447
|
-
- [aroundLatLng](#aroundlatlng) `search`
|
448
|
-
- [aroundLatLngViaIP](#aroundlatlngviaip) `search`
|
449
|
-
- [aroundRadius](#aroundradius) `search`
|
450
|
-
- [aroundPrecision](#aroundprecision) `search`
|
451
|
-
- [minimumAroundRadius](#minimumaroundradius) `search`
|
452
|
-
- [insideBoundingBox](#insideboundingbox) `search`
|
453
|
-
- [insidePolygon](#insidepolygon) `search`
|
454
|
-
|
455
|
-
**Query Strategy**
|
456
|
-
|
457
|
-
- [queryType](#querytype) `search`, `settings`
|
458
|
-
- [removeWordsIfNoResults](#removewordsifnoresults) `settings`, `search`
|
459
|
-
- [advancedSyntax](#advancedsyntax) `settings`, `search`
|
460
|
-
- [optionalWords](#optionalwords) `settings`, `search`
|
461
|
-
- [removeStopWords](#removestopwords) `settings`, `search`
|
462
|
-
- [exactOnSingleWordQuery](#exactonsinglewordquery) `settings`, `search`
|
463
|
-
- [alternativesAsExact](#alternativesasexact) `setting`, `search`
|
464
|
-
|
465
|
-
**Advanced**
|
466
|
-
|
467
|
-
- [distinct](#distinct) `settings`, `search`
|
468
|
-
- [getRankingInfo](#getrankinginfo) `search`
|
469
|
-
- [numericFilters](#numericfilters) `search`
|
470
|
-
- [tagFilters](#tagfilters) `search`
|
471
|
-
- [analytics](#analytics) `search`
|
472
|
-
- [analyticsTags](#analyticstags) `search`
|
473
|
-
- [synonyms](#synonyms) `search`
|
474
|
-
- [replaceSynonymsInHighlight](#replacesynonymsinhighlight) `settings`, `search`
|
475
|
-
- [minProximity](#minproximity) `settings`, `search`
|
476
|
-
- [responseFields](#responsefields) `settings`, `search`
|
477
|
-
|
478
|
-
## Search multiple indices - `multiple_queries`
|
479
|
-
|
480
|
-
You can send multiple queries with a single API call using a batch of queries:
|
481
|
-
|
482
|
-
```ruby
|
483
|
-
# perform 3 queries in a single API call:
|
484
|
-
# - 1st query targets index `categories`
|
485
|
-
# - 2nd and 3rd queries target index `products`
|
486
|
-
res = Algolia.multiple_queries([
|
487
|
-
,
|
488
|
-
, ])
|
489
|
-
|
490
|
-
puts res["results"]
|
491
|
-
```
|
492
|
-
|
493
|
-
You can specify a `strategy` parameter to optimize your multiple queries:
|
494
|
-
|
495
|
-
- `none`: Execute the sequence of queries until the end.
|
496
|
-
- `stopIfEnoughMatches`: Execute the sequence of queries until the number of hits is reached by the sum of hits.
|
497
|
-
|
498
|
-
### Response
|
499
|
-
|
500
|
-
The resulting JSON contains the following fields:
|
501
|
-
|
502
|
-
- `results` (array): The results for each request, in the order they were submitted. The contents are the same as in [Search an index](#search-an-index).
|
503
|
-
Each result also includes the following additional fields:
|
504
|
-
|
505
|
-
- `index` (string): The name of the targeted index.
|
506
|
-
- `processed` (boolean, optional): *Note: Only returned when `strategy` is `stopIfEnoughmatches`.* Whether the query was processed.
|
507
|
-
|
508
|
-
## Get Objects - `get_objects`
|
509
|
-
|
510
|
-
You can easily retrieve an object using its `objectID` and optionally specify a comma separated list of attributes you want:
|
511
|
-
|
512
|
-
```ruby
|
513
|
-
# Retrieves all attributes
|
514
|
-
index.get_object("myID")
|
515
|
-
# Retrieves firstname and lastname attributes
|
516
|
-
res = index.get_object("myID", "firstname,lastname")
|
517
|
-
# Retrieves only the firstname attribute
|
518
|
-
res = index.get_object("myID", "firstname")
|
519
|
-
```
|
520
|
-
|
521
|
-
You can also retrieve a set of objects:
|
522
|
-
|
523
|
-
```ruby
|
524
|
-
res = index.get_objects(["myID", "myID2"])
|
525
|
-
```
|
526
|
-
|
527
|
-
## Search for facet values - `search_for_facet_values`
|
528
|
-
|
529
|
-
When a facet can take many different values, it can be useful to search within them. The typical use case is to build
|
530
|
-
an autocomplete menu for facet refinements, but of course other use cases may apply as well.
|
531
|
-
|
532
|
-
The facet search is different from a regular search in the sense that it retrieves *facet values*, not *objects*.
|
533
|
-
In other words, a value will only be returned once, even if it matches many different objects. How many objects it
|
534
|
-
matches is indicated by a count.
|
535
|
-
|
536
|
-
The results are sorted by decreasing count. Maximum 10 results are returned. No pagination is possible.
|
537
|
-
|
538
|
-
The facet search can optionally be restricted by a regular search query. In that case, it will return only facet values
|
539
|
-
that both:
|
540
|
-
|
541
|
-
1. match the facet query; and
|
542
|
-
2. are contained in objects matching the regular search query.
|
543
|
-
|
544
|
-
**Warning:** For a facet to be searchable, it must have been declared with the `searchable()` modifier in the [attributesForFaceting](#attributesforfaceting) index setting.
|
545
|
-
|
546
|
-
#### Example
|
547
|
-
|
548
|
-
Let's imagine we have objects similar to this one:
|
549
|
-
|
550
|
-
```json
|
551
|
-
{
|
552
|
-
"name": "iPhone 7 Plus",
|
553
|
-
"brand": "Apple",
|
554
|
-
"category": [
|
555
|
-
"Mobile phones",
|
556
|
-
"Electronics"
|
557
|
-
]
|
558
|
-
}
|
559
|
-
```
|
560
|
-
|
561
|
-
Then:
|
562
|
-
|
563
|
-
```ruby
|
564
|
-
# Search the values of the "category" facet matching "phone".
|
565
|
-
index.search_for_facet_values 'category', 'phone'
|
566
|
-
```
|
567
|
-
|
568
|
-
... could return:
|
569
|
-
|
570
|
-
```json
|
571
|
-
{
|
572
|
-
"facetHits": [
|
573
|
-
{
|
574
|
-
"value": "Mobile phones",
|
575
|
-
"highlighted": "Mobile <em>phone</em>s",
|
576
|
-
"count": 507
|
577
|
-
},
|
578
|
-
{
|
579
|
-
"value": "Phone cases",
|
580
|
-
"highlighted": "<em>Phone</em> cases",
|
581
|
-
"count": 63
|
582
|
-
}
|
583
|
-
]
|
584
|
-
}
|
585
|
-
```
|
586
|
-
|
587
|
-
Let's filter with an additional, regular search query:
|
588
|
-
|
589
|
-
```ruby
|
590
|
-
query = {
|
591
|
-
:filters => 'brand:Apple'
|
592
|
-
}
|
593
|
-
# Search the "category" facet for values matching "phone" in records
|
594
|
-
# having "Apple" in their "brand" facet.
|
595
|
-
index.search_for_facet_values 'category', 'phone', query
|
596
|
-
```
|
597
|
-
|
598
|
-
... could return:
|
599
|
-
|
600
|
-
```json
|
601
|
-
{
|
602
|
-
"facetHits": [
|
603
|
-
{
|
604
|
-
"value": "Mobile phones",
|
605
|
-
"highlighted": "Mobile <em>phone</em>s",
|
606
|
-
"count": 41
|
607
|
-
}
|
608
|
-
]
|
609
|
-
}
|
610
|
-
```
|
611
|
-
|
612
|
-
|
613
|
-
# Indexing
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
## Add Objects - `add_objects`
|
618
|
-
|
619
|
-
Each entry in an index has a unique identifier called `objectID`. There are two ways to add an entry to the index:
|
620
|
-
|
621
|
-
1. Supplying your own `objectID`.
|
622
|
-
2. Using automatic `objectID` assignment. You will be able to access it in the answer.
|
623
|
-
|
624
|
-
You don't need to explicitly create an index, it will be automatically created the first time you add an object.
|
625
|
-
Objects are schema less so you don't need any configuration to start indexing.
|
626
|
-
If you wish to configure things, the settings section provides details about advanced settings.
|
627
|
-
|
628
|
-
Example with automatic `objectID` assignments:
|
629
|
-
|
630
|
-
```ruby
|
631
|
-
res = index.add_objects([{"firstname" => "Jimmie",
|
632
|
-
"lastname" => "Barninger"},
|
633
|
-
{"firstname" => "Warren",
|
634
|
-
"lastname" => "Speach"}])
|
635
|
-
```
|
636
|
-
|
637
|
-
Example with manual `objectID` assignments:
|
638
|
-
|
639
|
-
```ruby
|
640
|
-
res = index.add_objects([{"objectID" => "1",
|
641
|
-
"firstname" => "Jimmie",
|
642
|
-
"lastname" => "Barninger"},
|
643
|
-
{"objectID" => "2",
|
644
|
-
"firstname" => "Warren",
|
645
|
-
"lastname" => "Speach"}])
|
646
|
-
```
|
647
|
-
|
648
|
-
To add a single object, use the [Add Objects](#add-objects) method:
|
649
|
-
|
650
|
-
```ruby
|
651
|
-
res = index.add_object({"firstname" => "Jimmie",
|
652
|
-
"lastname" => "Barninger"}, "myID")
|
653
|
-
puts "ObjectID=" + res["objectID"]
|
654
|
-
```
|
655
|
-
|
656
|
-
## Update objects - `save_objects`
|
657
|
-
|
658
|
-
You have three options when updating an existing object:
|
659
|
-
|
660
|
-
1. Replace all its attributes.
|
661
|
-
2. Replace only some attributes.
|
662
|
-
3. Apply an operation to some attributes.
|
663
|
-
|
664
|
-
Example on how to replace all attributes existing objects:
|
665
|
-
|
666
|
-
```ruby
|
667
|
-
res = index.save_objects([{"firstname" => "Jimmie",
|
668
|
-
"lastname" => "Barninger",
|
669
|
-
"objectID" => "myID1"},
|
670
|
-
{"firstname" => "Warren",
|
671
|
-
"lastname" => "Speach",
|
672
|
-
"objectID" => "myID2"}])
|
673
|
-
```
|
674
|
-
|
675
|
-
To update a single object, you can use the following method:
|
676
|
-
|
677
|
-
```ruby
|
678
|
-
index.save_object({"firstname" => "Jimmie",
|
679
|
-
"lastname" => "Barninger",
|
680
|
-
"city" => "New York",
|
681
|
-
"objectID" => "myID"})
|
682
|
-
```
|
683
|
-
|
684
|
-
## Partial update objects - `partial_update_objects`
|
685
|
-
|
686
|
-
You have many ways to update an object's attributes:
|
687
|
-
|
688
|
-
1. Set the attribute value
|
689
|
-
2. Add a string or number element to an array
|
690
|
-
3. Remove an element from an array
|
691
|
-
4. Add a string or number element to an array if it doesn't exist
|
692
|
-
5. Increment an attribute
|
693
|
-
6. Decrement an attribute
|
694
|
-
|
695
|
-
Example to update only the city attribute of an existing object:
|
696
|
-
|
697
|
-
```ruby
|
698
|
-
index.partial_update_object({"city" => "San Francisco",
|
699
|
-
"objectID" => "myID"})
|
700
|
-
```
|
701
|
-
|
702
|
-
Example to add a tag:
|
703
|
-
|
704
|
-
```ruby
|
705
|
-
index.partial_update_object({"_tags" => {"value" => "MyTag", "_operation" => "Add"},
|
706
|
-
"objectID" => "myID"})
|
707
|
-
```
|
708
|
-
|
709
|
-
Example to remove a tag:
|
710
|
-
|
711
|
-
```ruby
|
712
|
-
index.partial_update_object({"_tags" => {"value" => "MyTag", "_operation" => "Remove"},
|
713
|
-
"objectID" => "myID"})
|
714
|
-
```
|
715
|
-
|
716
|
-
Example to add a tag if it doesn't exist:
|
717
|
-
|
718
|
-
```ruby
|
719
|
-
index.partial_update_object({"_tags" => {"value" => "MyTag", "_operation" => "AddUnique"},
|
720
|
-
"objectID" => "myID"})
|
721
|
-
```
|
722
|
-
|
723
|
-
Example to increment a numeric value:
|
724
|
-
|
725
|
-
```ruby
|
726
|
-
index.partial_update_object({"price" => {"value" => 42, "_operation" => "Increment"},
|
727
|
-
"objectID" => "myID"})
|
728
|
-
```
|
729
|
-
|
730
|
-
Note: Here we are incrementing the value by `42`. To increment just by one, put
|
731
|
-
`value:1`.
|
732
|
-
|
733
|
-
Example to decrement a numeric value:
|
734
|
-
|
735
|
-
```ruby
|
736
|
-
index.partial_update_object({"price" => {"value" => 42, "_operation" => "Decrement"},
|
737
|
-
"objectID" => "myID"})
|
738
|
-
```
|
739
|
-
|
740
|
-
Note: Here we are decrementing the value by `42`. To decrement just by one, put
|
741
|
-
`value:1`.
|
742
|
-
|
743
|
-
To partial update multiple objects using one API call, you can use the following method:
|
744
|
-
|
745
|
-
```ruby
|
746
|
-
res = index.partial_update_objects([{"firstname" => "Jimmie",
|
747
|
-
"objectID" => "SFO"},
|
748
|
-
{"firstname" => "Warren",
|
749
|
-
"objectID" => "myID2"}])
|
750
|
-
```
|
751
|
-
|
752
|
-
## Delete objects - `delete_objects`
|
753
|
-
|
754
|
-
You can delete objects using their `objectID`:
|
755
|
-
|
756
|
-
```ruby
|
757
|
-
res = index.delete_objects(["myID1", "myID2"])
|
758
|
-
```
|
759
|
-
|
760
|
-
To delete a single object, you can use the following method:
|
761
|
-
|
762
|
-
```ruby
|
763
|
-
index.delete_object("myID")
|
764
|
-
```
|
765
|
-
|
766
|
-
## Delete by query - `delete_by_query`
|
767
|
-
|
768
|
-
You can delete all objects matching a single query with the following code. Internally, the API client performs the query, deletes all matching hits, and waits until the deletions have been applied.
|
769
|
-
|
770
|
-
Take your precautions when using this method. Calling it with an empty query will result in cleaning the index of all its records.
|
771
|
-
|
772
|
-
```ruby
|
773
|
-
params = {}
|
774
|
-
index.delete_by_query("John", params)
|
775
|
-
```
|
776
|
-
|
777
|
-
## Wait for operations - `wait_task`
|
778
|
-
|
779
|
-
All write operations in Algolia are asynchronous by design.
|
780
|
-
|
781
|
-
It means that when you add or update an object to your index, our servers will
|
782
|
-
reply to your request with a `taskID` as soon as they understood the write
|
783
|
-
operation.
|
784
|
-
|
785
|
-
The actual insert and indexing will be done after replying to your code.
|
786
|
-
|
787
|
-
You can wait for a task to complete using the same method with a `!`.
|
788
|
-
|
789
|
-
For example, to wait for indexing of a new object:
|
790
|
-
|
791
|
-
```ruby
|
792
|
-
res = index.add_object!({"firstname" => "Jimmie",
|
793
|
-
"lastname" => "Barninger"})
|
794
|
-
```
|
795
|
-
|
796
|
-
If you want to ensure multiple objects have been indexed, you only need to check
|
797
|
-
the biggest `taskID` with `wait_task`.
|
798
|
-
|
155
|
+
- **Need help**? Ask a question to the [Algolia Community](https://discourse.algolia.com/) or on [Stack Overflow](http://stackoverflow.com/questions/tagged/algolia).
|
156
|
+
- **Found a bug?** You can open a [GitHub issue](https://github.com/algolia/algoliasearch-client-ruby/issues).
|
799
157
|
|
800
|
-
# Settings
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
## Get settings - `get_settings`
|
805
|
-
|
806
|
-
You can retrieve settings:
|
807
|
-
|
808
|
-
```ruby
|
809
|
-
settings = index.get_settings
|
810
|
-
puts settings.to_json
|
811
|
-
```
|
812
|
-
|
813
|
-
## Set settings - `set_settings`
|
814
|
-
|
815
|
-
```ruby
|
816
|
-
index.set_settings({"customRanking" => ["desc(followers)"]})
|
817
|
-
```
|
818
|
-
|
819
|
-
You can find the list of parameters you can set in the [Settings Parameters](#index-settings-parameters) section
|
820
|
-
|
821
|
-
**Warning**
|
822
|
-
|
823
|
-
Performance wise, it's better to do a `set_settings` before pushing the data
|
824
|
-
|
825
|
-
### Replica settings
|
826
|
-
|
827
|
-
You can forward all settings updates to the replicas of an index by using the `forwardToReplicas` option:
|
828
|
-
|
829
|
-
```ruby
|
830
|
-
index.set_settings({"customRanking" => ["desc(followers)"]}, {"forwardToReplicas" => true})
|
831
|
-
```
|
832
|
-
|
833
|
-
## Index settings parameters
|
834
|
-
|
835
|
-
Here is the list of parameters you can use with the set settings method (`settings` [scope](#scope)).
|
836
|
-
|
837
|
-
Parameters that can be overridden at search time also have the `search` [scope](#scope).
|
838
|
-
|
839
|
-
**Attributes**
|
840
|
-
|
841
|
-
- [searchableAttributes](#searchableattributes) `settings`
|
842
|
-
- [attributesForFaceting](#attributesforfaceting) `settings`
|
843
|
-
- [unretrievableAttributes](#unretrievableattributes) `settings`
|
844
|
-
- [attributesToRetrieve](#attributestoretrieve) `settings`, `search`
|
845
|
-
|
846
|
-
**Ranking**
|
847
|
-
|
848
|
-
- [ranking](#ranking) `settings`
|
849
|
-
- [customRanking](#customranking) `settings`
|
850
|
-
- [replicas](#replicas) `settings`
|
851
|
-
|
852
|
-
**Filtering / Faceting**
|
853
|
-
|
854
|
-
- [maxValuesPerFacet](#maxvaluesperfacet) `settings`, `search`
|
855
|
-
|
856
|
-
**Highlighting / Snippeting**
|
857
|
-
|
858
|
-
- [attributesToHighlight](#attributestohighlight) `settings`, `search`
|
859
|
-
- [attributesToSnippet](#attributestosnippet) `settings`, `search`
|
860
|
-
- [highlightPreTag](#highlightpretag) `settings`, `search`
|
861
|
-
- [highlightPostTag](#highlightposttag) `settings`, `search`
|
862
|
-
- [snippetEllipsisText](#snippetellipsistext) `settings`, `search`
|
863
|
-
- [restrictHighlightAndSnippetArrays](#restricthighlightandsnippetarrays) `settings`, `search`
|
864
|
-
|
865
|
-
**Pagination**
|
866
|
-
|
867
|
-
- [hitsPerPage](#hitsperpage) `settings`, `search`
|
868
|
-
- [paginationLimitedTo](#paginationlimitedto) `settings`
|
869
|
-
|
870
|
-
**Typos**
|
871
|
-
|
872
|
-
- [minWordSizefor1Typo](#minwordsizefor1typo) `settings`, `search`
|
873
|
-
- [minWordSizefor2Typos](#minwordsizefor2typos) `settings`, `search`
|
874
|
-
- [typoTolerance](#typotolerance) `settings`, `search`
|
875
|
-
- [allowTyposOnNumericTokens](#allowtyposonnumerictokens) `settings`, `search`
|
876
|
-
- [ignorePlurals](#ignoreplurals) `settings`, `search`
|
877
|
-
- [disableTypoToleranceOnAttributes](#disabletypotoleranceonattributes) `settings`, `search`
|
878
|
-
- [disableTypoToleranceOnWords](#disabletypotoleranceonwords) `settings`
|
879
|
-
- [separatorsToIndex](#separatorstoindex) `settings`
|
880
|
-
|
881
|
-
**Query Strategy**
|
882
|
-
|
883
|
-
- [queryType](#querytype) `search`, `settings`
|
884
|
-
- [removeWordsIfNoResults](#removewordsifnoresults) `settings`, `search`
|
885
|
-
- [advancedSyntax](#advancedsyntax) `settings`, `search`
|
886
|
-
- [optionalWords](#optionalwords) `settings`, `search`
|
887
|
-
- [removeStopWords](#removestopwords) `settings`, `search`
|
888
|
-
- [disablePrefixOnAttributes](#disableprefixonattributes) `settings`
|
889
|
-
- [disableExactOnAttributes](#disableexactonattributes) `settings`
|
890
|
-
- [exactOnSingleWordQuery](#exactonsinglewordquery) `settings`, `search`
|
891
|
-
|
892
|
-
**Performance**
|
893
|
-
|
894
|
-
- [numericAttributesForFiltering](#numericattributesforfiltering) `settings`
|
895
|
-
- [allowCompressionOfIntegerArray](#allowcompressionofintegerarray) `settings`
|
896
|
-
|
897
|
-
**Advanced**
|
898
|
-
|
899
|
-
- [attributeForDistinct](#attributefordistinct) `settings`
|
900
|
-
- [distinct](#distinct) `settings`, `search`
|
901
|
-
- [replaceSynonymsInHighlight](#replacesynonymsinhighlight) `settings`, `search`
|
902
|
-
- [placeholders](#placeholders) `settings`
|
903
|
-
- [altCorrections](#altcorrections) `settings`
|
904
|
-
- [minProximity](#minproximity) `settings`, `search`
|
905
|
-
- [responseFields](#responsefields) `settings`, `search`
|
906
|
-
|
907
|
-
|
908
|
-
# Parameters
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
## Overview
|
913
|
-
|
914
|
-
### Scope
|
915
|
-
|
916
|
-
Each parameter in this page has a scope. Depending on the scope, you can use the parameter within the `setSettings`
|
917
|
-
and/or the `search` method.
|
918
|
-
|
919
|
-
There are three scopes:
|
920
|
-
|
921
|
-
- `settings`: The setting can only be used in the `setSettings` method.
|
922
|
-
- `search`: The setting can only be used in the `search` method.
|
923
|
-
- `settings` `search`: The setting can be used in the `setSettings` method and be overridden in the`search` method.
|
924
|
-
|
925
|
-
### Parameters List
|
926
|
-
|
927
|
-
**Search**
|
928
|
-
|
929
|
-
- [query](#query) `search`
|
930
|
-
|
931
|
-
**Attributes**
|
932
|
-
|
933
|
-
- [searchableAttributes](#searchableattributes) `settings`
|
934
|
-
- [attributesForFaceting](#attributesforfaceting) `settings`
|
935
|
-
- [unretrievableAttributes](#unretrievableattributes) `settings`
|
936
|
-
- [attributesToRetrieve](#attributestoretrieve) `settings`, `search`
|
937
|
-
- [restrictSearchableAttributes](#restrictsearchableattributes) `search`
|
938
|
-
|
939
|
-
**Ranking**
|
940
|
-
|
941
|
-
- [ranking](#ranking) `settings`
|
942
|
-
- [customRanking](#customranking) `settings`
|
943
|
-
- [replicas](#replicas) `settings`
|
944
|
-
|
945
|
-
**Filtering / Faceting**
|
946
|
-
|
947
|
-
- [filters](#filters) `search`
|
948
|
-
- [facets](#facets) `search`
|
949
|
-
- [maxValuesPerFacet](#maxvaluesperfacet) `settings`, `search`
|
950
|
-
- [facetFilters](#facetfilters) `search`
|
951
|
-
|
952
|
-
**Highlighting / Snippeting**
|
953
|
-
|
954
|
-
- [attributesToHighlight](#attributestohighlight) `settings`, `search`
|
955
|
-
- [attributesToSnippet](#attributestosnippet) `settings`, `search`
|
956
|
-
- [highlightPreTag](#highlightpretag) `settings`, `search`
|
957
|
-
- [highlightPostTag](#highlightposttag) `settings`, `search`
|
958
|
-
- [snippetEllipsisText](#snippetellipsistext) `settings`, `search`
|
959
|
-
- [restrictHighlightAndSnippetArrays](#restricthighlightandsnippetarrays) `settings`, `search`
|
960
|
-
|
961
|
-
**Pagination**
|
962
|
-
|
963
|
-
- [page](#page) `search`
|
964
|
-
- [hitsPerPage](#hitsperpage) `settings`, `search`
|
965
|
-
- [offset](#offset) `search`
|
966
|
-
- [length](#length) `search`
|
967
|
-
- [paginationLimitedTo](#paginationlimitedto) `settings`
|
968
|
-
|
969
|
-
**Typos**
|
970
|
-
|
971
|
-
- [minWordSizefor1Typo](#minwordsizefor1typo) `settings`, `search`
|
972
|
-
- [minWordSizefor2Typos](#minwordsizefor2typos) `settings`, `search`
|
973
|
-
- [typoTolerance](#typotolerance) `settings`, `search`
|
974
|
-
- [allowTyposOnNumericTokens](#allowtyposonnumerictokens) `settings`, `search`
|
975
|
-
- [ignorePlurals](#ignoreplurals) `settings`, `search`
|
976
|
-
- [disableTypoToleranceOnAttributes](#disabletypotoleranceonattributes) `settings`, `search`
|
977
|
-
- [disableTypoToleranceOnWords](#disabletypotoleranceonwords) `settings`
|
978
|
-
- [separatorsToIndex](#separatorstoindex) `settings`
|
979
|
-
|
980
|
-
**Geo-Search**
|
981
|
-
|
982
|
-
- [aroundLatLng](#aroundlatlng) `search`
|
983
|
-
- [aroundLatLngViaIP](#aroundlatlngviaip) `search`
|
984
|
-
- [aroundRadius](#aroundradius) `search`
|
985
|
-
- [aroundPrecision](#aroundprecision) `search`
|
986
|
-
- [minimumAroundRadius](#minimumaroundradius) `search`
|
987
|
-
- [insideBoundingBox](#insideboundingbox) `search`
|
988
|
-
- [insidePolygon](#insidepolygon) `search`
|
989
|
-
|
990
|
-
**Query Strategy**
|
991
|
-
|
992
|
-
- [queryType](#querytype) `search`, `settings`
|
993
|
-
- [removeWordsIfNoResults](#removewordsifnoresults) `settings`, `search`
|
994
|
-
- [advancedSyntax](#advancedsyntax) `settings`, `search`
|
995
|
-
- [optionalWords](#optionalwords) `settings`, `search`
|
996
|
-
- [removeStopWords](#removestopwords) `settings`, `search`
|
997
|
-
- [disablePrefixOnAttributes](#disableprefixonattributes) `settings`
|
998
|
-
- [disableExactOnAttributes](#disableexactonattributes) `settings`
|
999
|
-
- [exactOnSingleWordQuery](#exactonsinglewordquery) `settings`, `search`
|
1000
|
-
- [alternativesAsExact](#alternativesasexact) `setting`, `search`
|
1001
|
-
|
1002
|
-
**Performance**
|
1003
|
-
|
1004
|
-
- [numericAttributesForFiltering](#numericattributesforfiltering) `settings`
|
1005
|
-
- [allowCompressionOfIntegerArray](#allowcompressionofintegerarray) `settings`
|
1006
|
-
|
1007
|
-
**Advanced**
|
1008
|
-
|
1009
|
-
- [attributeForDistinct](#attributefordistinct) `settings`
|
1010
|
-
- [distinct](#distinct) `settings`, `search`
|
1011
|
-
- [getRankingInfo](#getrankinginfo) `search`
|
1012
|
-
- [numericFilters](#numericfilters) `search`
|
1013
|
-
- [tagFilters](#tagfilters) `search`
|
1014
|
-
- [analytics](#analytics) `search`
|
1015
|
-
- [analyticsTags](#analyticstags) `search`
|
1016
|
-
- [synonyms](#synonyms) `search`
|
1017
|
-
- [replaceSynonymsInHighlight](#replacesynonymsinhighlight) `settings`, `search`
|
1018
|
-
- [placeholders](#placeholders) `settings`
|
1019
|
-
- [altCorrections](#altcorrections) `settings`
|
1020
|
-
- [minProximity](#minproximity) `settings`, `search`
|
1021
|
-
- [responseFields](#responsefields) `settings`, `search`
|
1022
|
-
|
1023
|
-
## Search
|
1024
|
-
|
1025
|
-
#### query
|
1026
|
-
|
1027
|
-
- scope: `search`
|
1028
|
-
- type: string
|
1029
|
-
- default: `""`
|
1030
|
-
|
1031
|
-
The text to search for in the index. If empty or absent, the textual search will match any object.
|
1032
|
-
|
1033
|
-
## Attributes
|
1034
|
-
|
1035
|
-
#### searchableAttributes
|
1036
|
-
|
1037
|
-
- scope: `settings`
|
1038
|
-
- type: array of strings
|
1039
|
-
- default: `[]` (all string attributes)
|
1040
|
-
- formerly known as: `attributesToIndex`
|
1041
|
-
|
1042
|
-
List of attributes eligible for textual search.
|
1043
|
-
In search engine parlance, those attributes will be "indexed", i.e. their content will be made searchable.
|
1044
|
-
|
1045
|
-
If not specified or empty, all string values of all attributes are indexed.
|
1046
|
-
If specified, only the specified attributes are indexed; any numerical values within those attributes are converted to strings and indexed.
|
1047
|
-
|
1048
|
-
When an attribute is listed, it is *recursively* processed, i.e. all of its nested attributes, at any depth, are indexed
|
1049
|
-
according to the same policy.
|
1050
|
-
|
1051
|
-
**Note:** Make sure you adjust this setting to get optimal results.
|
1052
|
-
|
1053
|
-
This parameter has two important uses:
|
1054
|
-
|
1055
|
-
1. **Limit the scope of the search.**
|
1056
|
-
Restricting the searchable attributes to those containing meaningful text guarantees a better relevance.
|
1057
|
-
For example, if your objects have associated pictures, you need to store the picture URLs in the records
|
1058
|
-
in order to retrieve them for display at query time, but you probably don't want to *search* inside the URLs.
|
1059
|
-
|
1060
|
-
A side effect of limiting the attributes is **increased performance**: it keeps the index size at a minimum, which
|
1061
|
-
has a direct and positive impact on both build time and search speed.
|
1062
|
-
|
1063
|
-
2. **Control part of the ranking.** The contents of the `searchableAttributes` parameter impacts ranking in two complementary ways:
|
1064
|
-
|
1065
|
-
- **Attribute priority**: The order in which attributes are listed defines their ranking priority:
|
1066
|
-
matches in attributes at the beginning of the list will be considered more important than matches in
|
1067
|
-
attributes further down the list.
|
1068
|
-
|
1069
|
-
To assign the same priority to several attributes, pass them within the same string, separated by commas.
|
1070
|
-
For example, by specifying `["title,alternative_title", "text"]`, `title` and `alternative_title` will have
|
1071
|
-
the same priority, but a higher priority than `text`.
|
1072
|
-
|
1073
|
-
- **Importance of word positions**: Within a given attribute, matches near the beginning of the text are considered more
|
1074
|
-
important than matches near the end.
|
1075
|
-
You can disable this behavior by wrapping your attribute name inside an `unordered()` modifier.
|
1076
|
-
For example, `["title", "unordered(text)"]` will consider all positions inside the `text` attribute as equal,
|
1077
|
-
but positions inside the `title` attribute will still matter.
|
1078
|
-
|
1079
|
-
**Note:** To get a full description of how the ranking works, you can have a look at our [Ranking guide](https://www.algolia.com/doc/guides/relevance/ranking).
|
1080
|
-
|
1081
|
-
#### attributesForFaceting
|
1082
|
-
|
1083
|
-
- scope: `settings`
|
1084
|
-
- type: array of strings
|
1085
|
-
- default: `[]`
|
1086
|
-
|
1087
|
-
List of attributes you want to use for faceting.
|
1088
|
-
|
1089
|
-
All strings within these attributes will be extracted and added as facets.
|
1090
|
-
If not specified or empty, no attribute will be faceted.
|
1091
|
-
|
1092
|
-
If you only need to filter on a given facet, but are not interested in value counts for this facet,
|
1093
|
-
you can improve performances by specifying `filterOnly(${attributeName})`. This decreases the size of the index
|
1094
|
-
and the time required to build it.
|
1095
|
-
|
1096
|
-
If you want to search inside values of a given facet (using the [Search for facet values](#search-for-facet-values) method)
|
1097
|
-
you need to specify `searchable(${attributeName})`.
|
1098
|
-
|
1099
|
-
**Note:** The `filterOnly()` and `searchable()` modifiers are mutually exclusive.
|
1100
|
-
|
1101
|
-
#### unretrievableAttributes
|
1102
|
-
|
1103
|
-
- scope: `settings`
|
1104
|
-
- type: array of strings
|
1105
|
-
- default: `[]`
|
1106
|
-
|
1107
|
-
List of attributes that cannot be retrieved at query time.
|
1108
|
-
|
1109
|
-
These attributes can still be used for indexing and/or ranking.
|
1110
|
-
|
1111
|
-
**Note:** This setting is bypassed when the query is authenticated with the **admin API key**.
|
1112
|
-
|
1113
|
-
#### attributesToRetrieve
|
1114
|
-
|
1115
|
-
- scope: `settings` `search`
|
1116
|
-
- type: array of strings
|
1117
|
-
- default: `*` (all attributes)
|
1118
|
-
- formerly known as: `attributes`
|
1119
|
-
|
1120
|
-
List of object attributes you want to retrieve.
|
1121
|
-
This can be used to minimize the size of the response.
|
1122
|
-
|
1123
|
-
You can use `*` to retrieve all values.
|
1124
|
-
|
1125
|
-
**Note:** `objectID` is always retrieved, even when not specified.
|
1126
|
-
|
1127
|
-
**Note:** Attributes listed in [unretrievableAttributes](#unretrievableattributes) will not be retrieved even if requested,
|
1128
|
-
unless the request is authenticated with the admin API key.
|
1129
|
-
|
1130
|
-
#### restrictSearchableAttributes
|
1131
|
-
|
1132
|
-
- scope: `search`
|
1133
|
-
- type: array of strings
|
1134
|
-
- default: all attributes in `searchableAttributes`
|
1135
|
-
|
1136
|
-
List of attributes to be considered for textual search.
|
1137
|
-
|
1138
|
-
**Note:** It must be a subset of the [searchableAttributes](#searchableattributes) index setting.
|
1139
|
-
Consequently, `searchableAttributes` must not be empty nor null for `restrictSearchableAttributes` to be allowed.
|
1140
|
-
|
1141
|
-
## Ranking
|
1142
|
-
|
1143
|
-
#### ranking
|
1144
|
-
|
1145
|
-
- scope: `settings`
|
1146
|
-
- type: array of strings
|
1147
|
-
- default: `["typo", "geo", "words", "filters", "proximity", "attribute", "exact", "custom"]`
|
1148
|
-
|
1149
|
-
Controls the way results are sorted.
|
1150
|
-
|
1151
|
-
You must specify a list of ranking criteria. They will be applied in sequence by the tie-breaking algorithm
|
1152
|
-
in the order they are specified.
|
1153
|
-
|
1154
|
-
The following ranking criteria are available:
|
1155
|
-
|
1156
|
-
* `typo`: Sort by increasing number of typos.
|
1157
|
-
* `geo`: Sort by decreasing geo distance when performing a geo search.
|
1158
|
-
This criterion is ignored when not performing a geo search.
|
1159
|
-
* `words`: Sort by decreasing number of matched query words.
|
1160
|
-
This parameter is useful when you use the [optionalWords](#optionalwords) query parameter to rank hits with the most matched words first.
|
1161
|
-
* `proximity`: Sort by increasing proximity of query words in hits.
|
1162
|
-
* `attribute`: Sort according to the order of attributes defined by [searchableAttributes](#searchableattributes).
|
1163
|
-
* `exact`:
|
1164
|
-
- **If the query contains only one word:** The behavior depends on the value of [exactOnSingleWordQuery](#exactonsinglewordquery).
|
1165
|
-
- **If the query contains multiple words:** Sort by decreasing number of words that matched exactly.
|
1166
|
-
What is considered to be an exact match depends on the value of [alternativesAsExact](#alternativesasexact).
|
1167
|
-
* `custom`: Sort according to a user-defined formula specified via the [customRanking](#customranking) setting.
|
1168
|
-
* Sort by value of a numeric attribute. Here, `${attributeName}` can be the name of any numeric attribute in your objects (integer, floating-point or boolean).
|
1169
|
-
* `asc(${attributeName})`: sort by increasing value of the attribute
|
1170
|
-
* `desc(${attributeName})`: sort by decreasing value of the attribute
|
1171
|
-
|
1172
|
-
**Note:** To get a full description of how the ranking works, you can have a look at our [Ranking guide](https://www.algolia.com/doc/guides/relevance/ranking).
|
1173
|
-
|
1174
|
-
#### customRanking
|
1175
|
-
|
1176
|
-
- scope: `settings`
|
1177
|
-
- type: array of strings
|
1178
|
-
- default: `[]`
|
1179
|
-
|
1180
|
-
Specifies the `custom` ranking criterion.
|
1181
|
-
|
1182
|
-
Each string must conform to the syntax `asc(${attributeName})` or `desc(${attributeName})` and specifies a
|
1183
|
-
(respectively) increasing or decreasing sort on an attribute. All sorts are applied in sequence by the tie-breaking
|
1184
|
-
algorithm in the order they are specified.
|
1185
|
-
|
1186
|
-
**Example:** `["desc(population)", "asc(name)"]` will sort by decreasing value of the `population` attribute,
|
1187
|
-
then *in case of equality* by increasing value of the `name` attribute.
|
1188
|
-
|
1189
|
-
**Note:** To get a full description of how custom ranking works,
|
1190
|
-
you can have a look at our [Ranking guide](https://www.algolia.com/doc/guides/relevance/ranking).
|
1191
|
-
|
1192
|
-
#### replicas
|
1193
|
-
|
1194
|
-
- scope: `settings`
|
1195
|
-
- type: array of strings
|
1196
|
-
- default: `[]`
|
1197
|
-
- formerly known as: `slaves`
|
1198
|
-
|
1199
|
-
List of indices to which you want to replicate all write operations.
|
1200
|
-
|
1201
|
-
In order to get relevant results in milliseconds, we pre-compute part of the ranking during indexing.
|
1202
|
-
Consequently, if you want to use different ranking formulas depending on the use case,
|
1203
|
-
you need to create one index per ranking formula.
|
1204
|
-
|
1205
|
-
This option allows you to perform write operations on a single, master index and automatically
|
1206
|
-
perform the same operations on all of its replicas.
|
1207
|
-
|
1208
|
-
**Note:** A master index can have as many replicas as needed. However, a replica can only have one master; in other words,
|
1209
|
-
two master indices cannot have the same replica. Furthermore, a replica cannot have its own replicas
|
1210
|
-
(i.e. you cannot "chain" replicas).
|
1211
|
-
|
1212
|
-
## Filtering / Faceting
|
1213
|
-
|
1214
|
-
#### filters
|
1215
|
-
|
1216
|
-
- scope: `search`
|
1217
|
-
- type: string
|
1218
|
-
- default: `""`
|
1219
|
-
|
1220
|
-
Filter the query with numeric, facet and/or tag filters.
|
1221
|
-
|
1222
|
-
This parameter uses a SQL-like expression syntax, where you can use boolean operators and parentheses to combine individual filters.
|
1223
|
-
|
1224
|
-
The following **individual filters** are supported:
|
1225
|
-
|
1226
|
-
- **Numeric filter**:
|
1227
|
-
|
1228
|
-
- **Comparison**: `${attributeName} ${operator} ${operand}` matches all objects where the specified numeric attribute satisfies the numeric condition expressed by the operator and the operand. The operand must be a numeric value. Supported operators are `<`, `<=`, `=`, `!=`, `>=` and `>`, with the same semantics as in virtually all programming languages.
|
1229
|
-
Example: `inStock > 0`.
|
1230
|
-
|
1231
|
-
- **Range**: `${attributeName}:${lowerBound} TO ${upperBound}` matches all objects where the specified numeric
|
1232
|
-
attribute is within the range [`${lowerBound}`, `${upperBound}`] \(inclusive on both ends).
|
1233
|
-
Example: `publication_date: 1441745506 TO 1441755506`.
|
1234
|
-
|
1235
|
-
- **Facet filter**: `${facetName}:${facetValue}` matches all objects containing exactly the specified value in the specified facet attribute. *Facet matching is case sensitive*. Example: `category:Book`.
|
1236
|
-
|
1237
|
-
- **Tag filter**: `_tags:${value}` (or, alternatively, just `${value}`) matches all objects containing exactly the specified value in their `_tags` attribute. *Tag matching is case sensitive*. Example: `_tags:published`.
|
1238
|
-
|
1239
|
-
Individual filters can be combined via **boolean operators**. The following operators are supported:
|
1240
|
-
|
1241
|
-
- `OR`: must match any of the combined conditions (disjunction)
|
1242
|
-
- `AND`: must match all of the combined conditions (conjunction)
|
1243
|
-
- `NOT`: negate a filter
|
1244
|
-
|
1245
|
-
Finally, **parentheses** (`(` and `)`) can be used for grouping.
|
1246
|
-
|
1247
|
-
Putting it all together, an example is:
|
1248
|
-
|
1249
|
-
```
|
1250
|
-
available = 1 AND (category:Book OR NOT category:Ebook) AND _tags:published AND publication_date:1441745506 TO 1441755506 AND inStock > 0 AND author:"John Doe"
|
1251
|
-
```
|
1252
|
-
|
1253
|
-
**Warning:** Keywords are case-sensitive.
|
1254
|
-
|
1255
|
-
**Note:** If no attribute name is specified, the filter applies to `_tags`.
|
1256
|
-
For example: `public OR user_42` will translate into `_tags:public OR _tags:user_42`.
|
1257
|
-
|
1258
|
-
**Note:** If a value contains spaces, or conflicts with a keyword, you can use double quotes.
|
1259
|
-
|
1260
|
-
**Note:** If a filtered attribute contains an array of values, any matching value will cause the filter to match.
|
1261
|
-
|
1262
|
-
**Warning:** For performance reasons, filter expressions are limited to a disjunction of conjunctions.
|
1263
|
-
In other words, you can have ANDs of ORs (e.g. `filter1 AND (filter2 OR filter3)`),
|
1264
|
-
but not ORs of ANDs (e.g. `filter1 OR (filter2 AND filter3)`.
|
1265
|
-
|
1266
|
-
**Warning:** You cannot mix different filter categories inside a disjunction (OR).
|
1267
|
-
For example, `num=3 OR tag1 OR facet:value` is not allowed.
|
1268
|
-
|
1269
|
-
**Warning:** You cannot negate a group of filters, only an individual filter.
|
1270
|
-
For example, `NOT(filter1 OR filter2)` is not allowed.
|
1271
|
-
|
1272
|
-
#### facets
|
1273
|
-
|
1274
|
-
- scope: `search`
|
1275
|
-
- type: array of strings
|
1276
|
-
- default: `[]`
|
1277
|
-
|
1278
|
-
Facets to retrieve.
|
1279
|
-
If not specified or empty, no facets are retrieved.
|
1280
|
-
The special value `*` may be used to retrieve all facets.
|
1281
|
-
|
1282
|
-
**Warning:** Facets must have been declared beforehand in the [attributesForFaceting](#attributesforfaceting) index setting.
|
1283
|
-
|
1284
|
-
For each of the retrieved facets, the response will contain a list of the most frequent facet values in objects
|
1285
|
-
matching the current query. Each value will be returned with its associated count (number of matched objects containing that value).
|
1286
|
-
|
1287
|
-
**Warning:** Faceting does **not** filter your results. If you want to filter results, you should use [filters](#filters).
|
1288
|
-
|
1289
|
-
**Example**:
|
1290
|
-
|
1291
|
-
If your settings contain:
|
1292
|
-
|
1293
|
-
```
|
1294
|
-
{
|
1295
|
-
"attributesForFaceting": ["category", "author", "nb_views", "nb_downloads"]
|
1296
|
-
}
|
1297
|
-
```
|
1298
|
-
|
1299
|
-
... but, for the current search, you want to retrieve facet values only for `category` and `author`, then you can specify:
|
1300
|
-
|
1301
|
-
```
|
1302
|
-
"facets": ["category", "author"]
|
1303
|
-
```
|
1304
|
-
|
1305
|
-
**Warning:** If the number of hits is high, facet counts may be approximate.
|
1306
|
-
The response field `exhaustiveFacetsCount` is true when the count is exact.
|
1307
|
-
|
1308
|
-
#### maxValuesPerFacet
|
1309
|
-
|
1310
|
-
- scope: `settings` `search`
|
1311
|
-
- type: integer
|
1312
|
-
- default: `100`
|
1313
|
-
|
1314
|
-
Maximum number of facet values returned for each facet.
|
1315
|
-
|
1316
|
-
**Warning:** The API enforces a hard limit of 1000 on `maxValuesPerFacet`.
|
1317
|
-
Any value above that limit will be interpreted as 1000.
|
1318
|
-
|
1319
|
-
#### facetFilters
|
1320
|
-
|
1321
|
-
- scope: `search`
|
1322
|
-
- type: array of strings
|
1323
|
-
- default: `[]`
|
1324
|
-
|
1325
|
-
Filter hits by facet value.
|
1326
|
-
|
1327
|
-
**Note:** The [filters](#filters) parameter provides an easier to use, SQL-like syntax.
|
1328
|
-
We recommend using it instead of `facetFilters`.
|
1329
|
-
|
1330
|
-
Each string represents a filter on a given facet value. It must follow the syntax `${attributeName}:${value}`.
|
1331
|
-
|
1332
|
-
If you specify multiple filters, they are interpreted as a conjunction (AND). If you want to use a disjunction (OR),
|
1333
|
-
use a nested array.
|
1334
|
-
|
1335
|
-
Examples:
|
1336
|
-
|
1337
|
-
- `["category:Book", "author:John Doe"]` translates as `category:Book AND author:"John Doe"`
|
1338
|
-
- `[["category:Book", "category:Movie"], "author:John Doe"]` translates as `(category:Book OR category:Movie) AND author:"John Doe"`
|
1339
|
-
|
1340
|
-
Negation is supported by prefixing the value with a minus sign (`-`, a.k.a. dash).
|
1341
|
-
For example: `["category:Book", "category:-Movie"]` translates as `category:Book AND NOT category:Movie`.
|
1342
|
-
|
1343
|
-
## Highlighting / Snippeting
|
1344
|
-
|
1345
|
-
#### attributesToHighlight
|
1346
|
-
|
1347
|
-
- scope: `settings` `search`
|
1348
|
-
- type: array of strings
|
1349
|
-
- default: all searchable attributes
|
1350
|
-
|
1351
|
-
List of attributes to highlight.
|
1352
|
-
If set to null, all **searchable** attributes are highlighted (see [searchableAttributes](#searchableattributes)).
|
1353
|
-
The special value `*` may be used to highlight all attributes.
|
1354
|
-
|
1355
|
-
**Note:** Only string values can be highlighted. Numerics will be ignored.
|
1356
|
-
|
1357
|
-
When highlighting is enabled, each hit in the response will contain an additional `_highlightResult` object
|
1358
|
-
(provided that at least one of its attributes is highlighted) with the following fields:
|
1359
|
-
|
1360
|
-
<!-- TODO: Factorize the following with the "Search Response Format" section in the API Client doc. -->
|
1361
|
-
|
1362
|
-
- `value` (string): Markup text with occurrences highlighted.
|
1363
|
-
The tags used for highlighting are specified via [highlightPreTag](#highlightpretag) and [highlightPostTag](#highlightposttag).
|
1364
|
-
|
1365
|
-
- `matchLevel` (string, enum) = {`none` \| `partial` \| `full`}: Indicates how well the attribute matched the search query.
|
1366
|
-
|
1367
|
-
- `matchedWords` (array): List of words *from the query* that matched the object.
|
1368
|
-
|
1369
|
-
- `fullyHighlighted` (boolean): Whether the entire attribute value is highlighted.
|
1370
|
-
|
1371
|
-
#### attributesToSnippet
|
1372
|
-
|
1373
|
-
- scope: `settings` `search`
|
1374
|
-
- type: array of strings
|
1375
|
-
- default: `[]` (no attribute is snippeted)
|
1376
|
-
|
1377
|
-
List of attributes to snippet, with an optional maximum number of words to snippet.
|
1378
|
-
If set to null, no attributes are snippeted.
|
1379
|
-
The special value `*` may be used to snippet all attributes.
|
1380
|
-
|
1381
|
-
The syntax for each attribute is `${attributeName}:${nbWords}`.
|
1382
|
-
The number of words can be omitted, and defaults to 10.
|
1383
|
-
|
1384
|
-
**Note:** Only string values can be snippeted. Numerics will be ignored.
|
1385
|
-
|
1386
|
-
When snippeting is enabled, each hit in the response will contain an additional `_snippetResult` object
|
1387
|
-
(provided that at least one of its attributes is snippeted) with the following fields:
|
1388
|
-
|
1389
|
-
<!-- TODO: Factorize the following with the "Search Response Format" section in the API Client doc. -->
|
1390
|
-
|
1391
|
-
- `value` (string): Markup text with occurrences highlighted and optional ellipsis indicators.
|
1392
|
-
The tags used for highlighting are specified via [highlightPreTag](#highlightpretag) and [highlightPostTag](#highlightposttag).
|
1393
|
-
The text used to indicate ellipsis is specified via [snippetEllipsisText](#snippetellipsistext).
|
1394
|
-
|
1395
|
-
- `matchLevel` (string, enum) = {`none` \| `partial` \| `full`}: Indicates how well the attribute matched the search query.
|
1396
|
-
|
1397
|
-
#### highlightPreTag
|
1398
|
-
|
1399
|
-
- scope: `settings` `search`
|
1400
|
-
- type: string
|
1401
|
-
- default: `"<em>"`
|
1402
|
-
|
1403
|
-
String inserted before highlighted parts in highlight and snippet results.
|
1404
|
-
|
1405
|
-
#### highlightPostTag
|
1406
|
-
|
1407
|
-
- scope: `settings` `search`
|
1408
|
-
- type: string
|
1409
|
-
- default: `"</em>"`
|
1410
|
-
|
1411
|
-
String inserted after highlighted parts in highlight and snippet results.
|
1412
|
-
|
1413
|
-
#### snippetEllipsisText
|
1414
|
-
|
1415
|
-
- scope: `settings` `search`
|
1416
|
-
- type: string
|
1417
|
-
- default: `…` (U+2026)
|
1418
|
-
|
1419
|
-
String used as an ellipsis indicator when a snippet is truncated.
|
1420
|
-
|
1421
|
-
**Warning:** Defaults to an empty string for all accounts created before February 10th, 2016.
|
1422
|
-
Defaults to `…` (U+2026, HORIZONTAL ELLIPSIS) for accounts created after that date.
|
1423
|
-
|
1424
|
-
#### restrictHighlightAndSnippetArrays
|
1425
|
-
|
1426
|
-
- scope: `settings` `search`
|
1427
|
-
- type: boolean
|
1428
|
-
- default: `false`
|
1429
|
-
|
1430
|
-
When true, restrict arrays in highlight and snippet results to items that matched the query at least partially.
|
1431
|
-
When false, return all array items in highlight and snippet results.
|
1432
|
-
|
1433
|
-
## Pagination
|
1434
|
-
|
1435
|
-
#### page
|
1436
|
-
|
1437
|
-
- scope: `search`
|
1438
|
-
- type: integer
|
1439
|
-
- default: `0`
|
1440
|
-
|
1441
|
-
Number of the page to retrieve.
|
1442
|
-
|
1443
|
-
**Warning:** Page numbers are zero-based. Therefore, in order to retrieve the 10th page, you need to set `page=9`.
|
1444
|
-
|
1445
|
-
#### hitsPerPage
|
1446
|
-
|
1447
|
-
- scope: `settings` `search`
|
1448
|
-
- type: integer
|
1449
|
-
- default: `20`
|
1450
|
-
|
1451
|
-
Maximum number of hits per page.
|
1452
|
-
|
1453
|
-
#### offset
|
1454
|
-
|
1455
|
-
- scope: `search`
|
1456
|
-
- type: integer
|
1457
|
-
- default: `null`
|
1458
|
-
|
1459
|
-
Offset of the first hit to return (zero-based).
|
1460
|
-
|
1461
|
-
**Note:** In most cases, [page](#page)/[hitsPerPage](#hitsperpage) is the recommended method for pagination.
|
1462
|
-
|
1463
|
-
#### length
|
1464
|
-
|
1465
|
-
- scope: `search`
|
1466
|
-
- type: integer
|
1467
|
-
- default: `null`
|
1468
|
-
|
1469
|
-
Maximum number of hits to return.
|
1470
|
-
|
1471
|
-
**Note:** In most cases, [page](#page)/[hitsPerPage](#hitsperpage) is the recommended method for pagination.
|
1472
|
-
|
1473
|
-
#### paginationLimitedTo
|
1474
|
-
|
1475
|
-
- scope: `settings`
|
1476
|
-
- type: integer
|
1477
|
-
- default: `1000`
|
1478
|
-
|
1479
|
-
Maximum number of hits accessible via pagination.
|
1480
|
-
By default, this parameter is set to 1000 to guarantee good performance.
|
1481
|
-
|
1482
|
-
**Caution:** We recommend keeping the default value to guarantee excellent performance.
|
1483
|
-
Increasing the pagination limit will have a direct impact on the performance of search queries.
|
1484
|
-
A too high value will also make it very easy for anyone to retrieve ("scrape") your entire dataset.
|
1485
|
-
|
1486
|
-
## Typos
|
1487
|
-
|
1488
|
-
#### minWordSizefor1Typo
|
1489
|
-
|
1490
|
-
- scope: `settings` `search`
|
1491
|
-
- type: integer
|
1492
|
-
- default: `4`
|
1493
|
-
|
1494
|
-
Minimum number of characters a word in the query string must contain to accept matches with one typo.
|
1495
|
-
|
1496
|
-
#### minWordSizefor2Typos
|
1497
|
-
|
1498
|
-
- scope: `settings` `search`
|
1499
|
-
- type: integer
|
1500
|
-
- default: `8`
|
1501
|
-
|
1502
|
-
Minimum number of characters a word in the query string must contain to accept matches with two typos.
|
1503
|
-
|
1504
|
-
#### typoTolerance
|
1505
|
-
|
1506
|
-
- scope: `settings` `search`
|
1507
|
-
- type: string \| boolean
|
1508
|
-
- default: `true`
|
1509
|
-
|
1510
|
-
Controls whether typo tolerance is enabled and how it is applied:
|
1511
|
-
|
1512
|
-
* `true`:
|
1513
|
-
Typo tolerance is enabled and all matching hits are retrieved (default behavior).
|
1514
|
-
|
1515
|
-
* `false`:
|
1516
|
-
Typo tolerance is entirely disabled. Hits matching with only typos are not retrieved.
|
1517
|
-
|
1518
|
-
* `min`:
|
1519
|
-
Only keep results with the minimum number of typos. For example, if just one hit matches without typos, then all hits with only typos are not retrieved.
|
1520
|
-
|
1521
|
-
* `strict`:
|
1522
|
-
Hits matching with 2 typos or more are not retrieved if there are some hits matching without typos.
|
1523
|
-
This option is useful to avoid "false positives" as much as possible.
|
1524
|
-
|
1525
|
-
#### allowTyposOnNumericTokens
|
1526
|
-
|
1527
|
-
- scope: `settings` `search`
|
1528
|
-
- type: boolean
|
1529
|
-
- default: `true`
|
1530
|
-
|
1531
|
-
Whether to allow typos on numbers ("numeric tokens") in the query string.
|
1532
|
-
|
1533
|
-
When false, typo tolerance is disabled on numeric tokens.
|
1534
|
-
For example, the query `304` will match `30450` but not `40450`
|
1535
|
-
(which would have been the case with typo tolerance enabled).
|
1536
|
-
|
1537
|
-
**Note:** This option can be very useful on serial numbers and zip codes searches.
|
1538
|
-
|
1539
|
-
#### ignorePlurals
|
1540
|
-
|
1541
|
-
- scope: `settings` `search`
|
1542
|
-
- type: boolean \| array of strings
|
1543
|
-
- default: `false`
|
1544
|
-
|
1545
|
-
Consider singular and plurals forms a match without typo.
|
1546
|
-
For example, "car" and "cars", or "foot" and "feet" will be considered equivalent.
|
1547
|
-
|
1548
|
-
This parameter may be:
|
1549
|
-
|
1550
|
-
- a **boolean**: enable or disable plurals for all supported languages;
|
1551
|
-
- a **list of language ISO codes** for which plurals should be enabled.
|
1552
|
-
|
1553
|
-
This option is set to `false` by default.
|
1554
|
-
|
1555
|
-
List of supported languages with their associated ISO code:
|
1556
|
-
|
1557
|
-
Afrikaans=`af`, Arabic=`ar`, Azeri=`az`, Bulgarian=`bg`, Catalan=`ca`,
|
1558
|
-
Czech=`cs`, Welsh=`cy`, Danis=`da`, German=`de`, English=`en`,
|
1559
|
-
Esperanto=`eo`, Spanish=`es`, Estonian=`et`, Basque=`eu`, Finnish=`fi`,
|
1560
|
-
Faroese=`fo`, French=`fr`, Galician=`gl`, Hebrew=`he`, Hindi=`hi`,
|
1561
|
-
Hungarian=`hu`, Armenian=`hy`, Indonesian=`id`, Icelandic=`is`, Italian=`it`,
|
1562
|
-
Japanese=`ja`, Georgian=`ka`, Kazakh=`kk`, Korean=`ko`, Kyrgyz=`ky`,
|
1563
|
-
Lithuanian=`lt`, Maori=`mi`, Mongolian=`mn`, Marathi=`mr`, Malay=`ms`,
|
1564
|
-
Maltese=`mt`, Norwegian=`nb`, Dutch=`nl`, Northern Sotho=`ns`, Polish=`pl`,
|
1565
|
-
Pashto=`ps`, Portuguese=`pt`, Quechua=`qu`, Romanian=`ro`, Russian=`ru`,
|
1566
|
-
Slovak=`sk`, Albanian=`sq`, Swedish=`sv`, Swahili=`sw`, Tamil=`ta`,
|
1567
|
-
Telugu=`te`, Tagalog=`tl`, Tswana=`tn`, Turkish=`tr`, Tatar=`tt`
|
1568
|
-
|
1569
|
-
#### disableTypoToleranceOnAttributes
|
1570
|
-
|
1571
|
-
- scope: `settings` `search`
|
1572
|
-
- type: array of strings
|
1573
|
-
- default: `[]`
|
1574
|
-
|
1575
|
-
List of attributes on which you want to disable typo tolerance
|
1576
|
-
(must be a subset of the [searchableAttributes](#searchableattributes) index setting).
|
1577
|
-
|
1578
|
-
#### disableTypoToleranceOnWords
|
1579
|
-
|
1580
|
-
- scope: `settings`
|
1581
|
-
- type: array of strings
|
1582
|
-
- default: `[]`
|
1583
|
-
|
1584
|
-
List of words on which typo tolerance will be disabled.
|
1585
|
-
|
1586
|
-
#### separatorsToIndex
|
1587
|
-
|
1588
|
-
- scope: `settings`
|
1589
|
-
- type: string
|
1590
|
-
- default: `""`
|
1591
|
-
|
1592
|
-
Separators (punctuation characters) to index.
|
1593
|
-
|
1594
|
-
By default, separators are not indexed.
|
1595
|
-
|
1596
|
-
**Example:** Use `+#` to be able to search for "Google+" or "C#".
|
1597
|
-
|
1598
|
-
## Geo-Search
|
1599
|
-
|
1600
|
-
Geo search requires that you provide at least one geo location in each record at indexing time, under the `_geoloc` attribute. Each location must be an object with two numeric `lat` and `lng` attributes. You may specify either one location:
|
1601
|
-
|
1602
|
-
```json
|
1603
|
-
{
|
1604
|
-
"_geoloc": {
|
1605
|
-
"lat": 48.853409,
|
1606
|
-
"lng": 2.348800
|
1607
|
-
}
|
1608
|
-
}
|
1609
|
-
```
|
1610
|
-
|
1611
|
-
... or an array of locations:
|
1612
|
-
|
1613
|
-
```json
|
1614
|
-
{
|
1615
|
-
"_geoloc": [
|
1616
|
-
{
|
1617
|
-
"lat": 48.853409,
|
1618
|
-
"lng": 2.348800
|
1619
|
-
},
|
1620
|
-
{
|
1621
|
-
"lat": 48.547456,
|
1622
|
-
"lng": 2.972075
|
1623
|
-
}
|
1624
|
-
]
|
1625
|
-
}
|
1626
|
-
```
|
1627
|
-
|
1628
|
-
When performing a geo search (either via [aroundLatLng](#aroundlatlng) or [aroundLatLngViaIP](#aroundlatlngviaip)),
|
1629
|
-
the maximum distance is automatically guessed based on the density of the searched area.
|
1630
|
-
You may explicitly specify a maximum distance, however, via [aroundRadius](#aroundradius).
|
1631
|
-
|
1632
|
-
The precision for the ranking is set via [aroundPrecision](#aroundprecision).
|
1633
|
-
|
1634
|
-
#### aroundLatLng
|
1635
|
-
|
1636
|
-
- scope: `search`
|
1637
|
-
- type: (latitude, longitude) pair
|
1638
|
-
- default: `null`
|
1639
|
-
|
1640
|
-
Search for entries around a given location (specified as two floats separated by a comma).
|
1641
|
-
|
1642
|
-
For example, `aroundLatLng=47.316669,5.016670`.
|
1643
|
-
|
1644
|
-
<!-- TODO: Only document serialization format for the REST API. -->
|
1645
|
-
|
1646
|
-
#### aroundLatLngViaIP
|
1647
|
-
|
1648
|
-
- scope: `search`
|
1649
|
-
- type: boolean
|
1650
|
-
- default: `false`
|
1651
|
-
|
1652
|
-
Search for entries around a given location automatically computed from the requester's IP address.
|
1653
|
-
|
1654
|
-
**Warning:** If you are sending the request from your servers, you must set the `X-Forwarded-For` HTTP header with the client's IP
|
1655
|
-
address for it to be used as the basis for the computation of the search location.
|
1656
|
-
|
1657
|
-
#### aroundRadius
|
1658
|
-
|
1659
|
-
- scope: `search`
|
1660
|
-
- type: integer \| `"all"`
|
1661
|
-
- default: `null`
|
1662
|
-
|
1663
|
-
Maximum radius for geo search (in meters).
|
1664
|
-
|
1665
|
-
If set, only hits within the specified radius from the searched location will be returned.
|
1666
|
-
|
1667
|
-
If not set, the radius is automatically computed from the density of the searched area.
|
1668
|
-
You can retrieve the computed radius in the `automaticRadius` response field.
|
1669
|
-
You may also specify a minimum value for the automatic radius via [minimumAroundRadius](#minimumaroundradius).
|
1670
|
-
|
1671
|
-
The special value `all` causes the geo distance to be computed and taken into account for ranking, but without filtering;
|
1672
|
-
this option is faster than specifying a high integer value.
|
1673
|
-
|
1674
|
-
#### aroundPrecision
|
1675
|
-
|
1676
|
-
- scope: `search`
|
1677
|
-
- type: integer
|
1678
|
-
- default: `1`
|
1679
|
-
|
1680
|
-
Precision of geo search (in meters).
|
1681
|
-
|
1682
|
-
When ranking hits, geo distances are grouped into ranges of `aroundPrecision` size. All hits within the same range
|
1683
|
-
are considered equal with respect to the `geo` ranking parameter.
|
1684
|
-
|
1685
|
-
For example, if you set `aroundPrecision` to `100`, any two objects lying in the range `[0, 99m]` from the searched
|
1686
|
-
location will be considered equal; same for `[100, 199]`, `[200, 299]`, etc.
|
1687
|
-
|
1688
|
-
#### minimumAroundRadius
|
1689
|
-
|
1690
|
-
- scope: `search`
|
1691
|
-
- type: integer
|
1692
|
-
- default: `null`
|
1693
|
-
|
1694
|
-
Minimum radius used for a geo search when [aroundRadius](#aroundradius) is not set.
|
1695
|
-
|
1696
|
-
**Note:** This parameter is ignored when `aroundRadius` is set.
|
1697
|
-
|
1698
|
-
#### insideBoundingBox
|
1699
|
-
|
1700
|
-
- scope: `search`
|
1701
|
-
- type: geo rectangle(s)
|
1702
|
-
- default: `null`
|
1703
|
-
|
1704
|
-
Search inside a rectangular area (in geo coordinates).
|
1705
|
-
|
1706
|
-
The rectange is defined by two diagonally opposite points (hereafter `p1` and `p2`),
|
1707
|
-
hence by 4 floats: `p1Lat`, `p1Lng`, `p2Lat`, `p2Lng`.
|
1708
|
-
|
1709
|
-
For example:
|
1710
|
-
|
1711
|
-
`insideBoundingBox=47.3165,4.9665,47.3424,5.0201`
|
1712
|
-
|
1713
|
-
You may specify multiple bounding boxes, in which case the search will use the **union** (OR) of the rectangles.
|
1714
|
-
To specify multiple rectangles, pass either:
|
1715
|
-
|
1716
|
-
- more than 4 values (must be a multiple of 4: 8, 12...);
|
1717
|
-
example: `47.3165,4.9665,47.3424,5.0201,40.9234,2.1185,38.6430,1.9916`; or
|
1718
|
-
- an array of arrays of floats (each inner array must contain exactly 4 values);
|
1719
|
-
example: `[[47.3165, 4.9665, 47.3424, 5.0201], [40.9234, 2.1185, 38.6430, 1.9916]`.
|
1720
|
-
|
1721
|
-
#### insidePolygon
|
1722
|
-
|
1723
|
-
- scope: `search`
|
1724
|
-
- type: geo polygon(s)
|
1725
|
-
- default: `null`
|
1726
|
-
|
1727
|
-
Search inside a polygon (in geo coordinates).
|
1728
|
-
|
1729
|
-
The polygon is defined by a set of points (minimum 3), each defined by its latitude and longitude.
|
1730
|
-
You therefore need an even number of floats, with a minimum of 6: `p1Lat`, `p1Lng`, `p2Lat`, `p2Lng`, `p3Lat`, `p3Long`.
|
1731
|
-
|
1732
|
-
For example:
|
1733
|
-
|
1734
|
-
`insidePolygon=47.3165,4.9665,47.3424,5.0201,47.32,4.98`
|
1735
|
-
|
1736
|
-
You may specify multiple polygons, in which case the search will use the **union** (OR) of the polygons.
|
1737
|
-
To specify multiple polygons, pass an array of arrays of floats (each inner array must contain an even number of
|
1738
|
-
values, with a minimum of 6);
|
1739
|
-
example: `[[47.3165, 4.9665, 47.3424, 5.0201, 47.32, 4.9], [40.9234, 2.1185, 38.6430, 1.9916, 39.2587, 2.0104]]`.
|
1740
|
-
|
1741
|
-
## Query Strategy
|
1742
|
-
|
1743
|
-
#### queryType
|
1744
|
-
|
1745
|
-
- scope: `search` `settings`
|
1746
|
-
- type: string
|
1747
|
-
- default: `"prefixLast"`
|
1748
|
-
|
1749
|
-
Controls if and how query words are interpreted as prefixes.
|
1750
|
-
|
1751
|
-
It may be one of the following values:
|
1752
|
-
|
1753
|
-
* `prefixLast`:
|
1754
|
-
Only the last word is interpreted as a prefix (default behavior).
|
1755
|
-
|
1756
|
-
* `prefixAll`:
|
1757
|
-
All query words are interpreted as prefixes. This option is not recommended, as it tends to yield counterintuitive
|
1758
|
-
results and has a negative impact on performance.
|
1759
|
-
|
1760
|
-
* `prefixNone`:
|
1761
|
-
No query word is interpreted as a prefix. This option is not recommended, especially in an instant search setup,
|
1762
|
-
as the user will have to type the entire word(s) before getting any relevant results.
|
1763
|
-
|
1764
|
-
#### removeWordsIfNoResults
|
1765
|
-
|
1766
|
-
- scope: `settings` `search`
|
1767
|
-
- type: string
|
1768
|
-
- default: `"none"`
|
1769
|
-
|
1770
|
-
Selects a strategy to remove words from the query when it doesn't match any hits.
|
1771
|
-
|
1772
|
-
The goal is to avoid empty results by progressively loosening the query until hits are matched.
|
1773
|
-
|
1774
|
-
There are four different options:
|
1775
|
-
|
1776
|
-
- `none`:
|
1777
|
-
No specific processing is done when a query does not return any results (default behavior).
|
1778
|
-
|
1779
|
-
- `lastWords`:
|
1780
|
-
When a query does not return any results, treat the last word as optional.
|
1781
|
-
The process is repeated with words N-1, N-2, etc. until there are results, or the beginning of the query string has been reached.
|
1782
|
-
|
1783
|
-
- `firstWords`:
|
1784
|
-
When a query does not return any results, treat the first word as optional.
|
1785
|
-
The process is repeated with words 2, 3, etc. until there are results, or the end of the query string has been reached.
|
1786
|
-
|
1787
|
-
- `allOptional`:
|
1788
|
-
When a query does not return any results, make a second attempt treating all words as optional.
|
1789
|
-
This is equivalent to transforming the implicit AND operator applied between query words to an OR.
|
1790
|
-
|
1791
|
-
#### advancedSyntax
|
1792
|
-
|
1793
|
-
- scope: `settings` `search`
|
1794
|
-
- type: boolean
|
1795
|
-
- default: `false`
|
1796
|
-
|
1797
|
-
Enables the advanced query syntax.
|
1798
|
-
|
1799
|
-
This advanced syntax brings two additional features:
|
1800
|
-
|
1801
|
-
- **Phrase query**: a specific sequence of terms that must be matched next to one another.
|
1802
|
-
A phrase query needs to be surrounded by double quotes (`"`).
|
1803
|
-
For example, `"search engine"` will only match records having `search` next to `engine`.
|
1804
|
-
|
1805
|
-
Typo tolerance is disabled inside the phrase (i.e. within the quotes).
|
1806
|
-
|
1807
|
-
|
1808
|
-
- **Prohibit operator**: excludes records that contain a specific term.
|
1809
|
-
This term has to be prefixed by a minus (`-`, a.k.a dash).
|
1810
|
-
For example, `search -engine` will only match records containing `search` but not `engine`.
|
1811
|
-
|
1812
|
-
#### optionalWords
|
1813
|
-
|
1814
|
-
- scope: `settings` `search`
|
1815
|
-
- type: string \| array of strings
|
1816
|
-
- default: `[]`
|
1817
|
-
|
1818
|
-
List of words that should be considered as optional when found in the query.
|
1819
|
-
|
1820
|
-
This parameter can be useful when you want to do an **OR** between all words of the query.
|
1821
|
-
To do that you can set optionalWords equals to the search query.
|
1822
|
-
|
1823
|
-
```js
|
1824
|
-
var query = 'the query';
|
1825
|
-
var params = {'optionalWords': query};
|
1826
|
-
```
|
1827
|
-
|
1828
|
-
**Note:** You don't need to put commas between words.
|
1829
|
-
Each string will automatically be tokenized into words, all of which will be considered as optional.
|
1830
|
-
|
1831
|
-
#### removeStopWords
|
1832
|
-
|
1833
|
-
- scope: `settings` `search`
|
1834
|
-
- type: boolean \| array of strings
|
1835
|
-
- default: `false`
|
1836
|
-
|
1837
|
-
Remove stop words from the query **before** executing it.
|
1838
|
-
|
1839
|
-
This parameter may be:
|
1840
|
-
|
1841
|
-
- a **boolean**: enable or disable stop words for all supported languages; or
|
1842
|
-
- a **list of language ISO codes** for which stop word removal should be enabled.
|
1843
|
-
|
1844
|
-
**Warning:** In most use-cases, **we don't recommend enabling stop word removal**.
|
1845
|
-
|
1846
|
-
Stop word removal is useful when you have a query in natural language, e.g. "what is a record?".
|
1847
|
-
In that case, the engine will remove "what", "is" and "a" before executing the query, and therefore just search for "record".
|
1848
|
-
This will remove false positives caused by stop words, especially when combined with optional words
|
1849
|
-
(see [optionalWords](#optionalwords) and [removeWordsIfNoResults](#removewordsifnoresults)).
|
1850
|
-
For most use cases, however, it is better not to use this feature, as people tend to search by keywords on search engines
|
1851
|
-
(i.e. they naturally omit stop words).
|
1852
|
-
|
1853
|
-
**Note:** Stop words removal is only applied on query words that are *not* interpreted as prefixes.
|
1854
|
-
|
1855
|
-
As a consequence, the behavior of `removeStopWords` also depends on the [queryType](#querytype) parameter:
|
1856
|
-
|
1857
|
-
* `queryType=prefixLast` means the last query word is a prefix and won't be considered for stop word removal;
|
1858
|
-
* `queryType=prefixNone` means no query word is a prefix, therefore stop word removal will be applied to all query words;
|
1859
|
-
* `queryType=prefixAll` means all query words are prefixes, therefore no stop words will be removed.
|
1860
|
-
|
1861
|
-
List of supported languages with their associated ISO code:
|
1862
|
-
|
1863
|
-
Arabic=`ar`, Armenian=`hy`, Basque=`eu`, Bengali=`bn`, Brazilian=`pt-br`, Bulgarian=`bg`, Catalan=`ca`, Chinese=`zh`, Czech=`cs`, Danish=`da`, Dutch=`nl`, English=`en`, Finnish=`fi`, French=`fr`, Galician=`gl`, German=`de`, Greek=`el`, Hindi=`hi`, Hungarian=`hu`, Indonesian=`id`, Irish=`ga`, Italian=`it`, Japanese=`ja`, Korean=`ko`, Kurdish=`ku`, Latvian=`lv`, Lithuanian=`lt`, Marathi=`mr`, Norwegian=`no`, Persian (Farsi)=`fa`, Polish=`pl`, Portugese=`pt`, Romanian=`ro`, Russian=`ru`, Slovak=`sk`, Spanish=`es`, Swedish=`sv`, Thai=`th`, Turkish=`tr`, Ukranian=`uk`, Urdu=`ur`.
|
1864
|
-
|
1865
|
-
#### disablePrefixOnAttributes
|
1866
|
-
|
1867
|
-
- scope: `settings`
|
1868
|
-
- type: array of strings
|
1869
|
-
- default: `[]`
|
1870
|
-
|
1871
|
-
List of attributes on which you want to disable prefix matching
|
1872
|
-
(must be a subset of the `searchableAttributes` index setting).
|
1873
|
-
|
1874
|
-
This setting is useful on attributes that contain string that should not be matched as a prefix
|
1875
|
-
(for example a product SKU).
|
1876
|
-
|
1877
|
-
#### disableExactOnAttributes
|
1878
|
-
|
1879
|
-
- scope: `settings`
|
1880
|
-
- type: search
|
1881
|
-
- default: `[]`
|
1882
|
-
|
1883
|
-
List of attributes on which you want to disable computation of the `exact` ranking criterion
|
1884
|
-
(must be a subset of the `searchableAttributes` index setting).
|
1885
|
-
|
1886
|
-
#### exactOnSingleWordQuery
|
1887
|
-
|
1888
|
-
- scope: `settings` `search`
|
1889
|
-
- type: string
|
1890
|
-
- default: `attribute`
|
1891
|
-
|
1892
|
-
Controls how the `exact` ranking criterion is computed when the query contains only one word.
|
1893
|
-
|
1894
|
-
The following values are allowed:
|
1895
|
-
|
1896
|
-
* `none`: the `exact` ranking criterion is ignored on single word queries;
|
1897
|
-
* `word`: the `exact` ranking criterion is set to 1 if the query word is found in the record.
|
1898
|
-
The query word must be at least 3 characters long and must not be a stop word in any supported language.
|
1899
|
-
* `attribute` (default): the `exact` ranking criterion is set to 1 if the query string exactly matches an entire attribute value.
|
1900
|
-
For example, if you search for the TV show "V", you want it to match the query "V" *before* all popular TV shows starting with the letter V.
|
1901
|
-
|
1902
|
-
#### alternativesAsExact
|
1903
|
-
|
1904
|
-
- scope: `setting` `search`
|
1905
|
-
- type: array of strings
|
1906
|
-
- default: `["ignorePlurals", "singleWordSynonym"]`
|
1907
|
-
|
1908
|
-
List of alternatives that should be considered an exact match by the `exact` ranking criterion.
|
1909
|
-
|
1910
|
-
The following values are allowed:
|
1911
|
-
|
1912
|
-
* `ignorePlurals`: alternative words added by the [ignorePlurals](#ignoreplurals) feature;
|
1913
|
-
* `singleWordSynonym`: single-word synonyms (example: "NY" = "NYC");
|
1914
|
-
* `multiWordsSynonym`: multiple-words synonyms (example: "NY" = "New York").
|
1915
|
-
|
1916
|
-
## Performance
|
1917
|
-
|
1918
|
-
#### numericAttributesForFiltering
|
1919
|
-
|
1920
|
-
- scope: `settings`
|
1921
|
-
- type: array of strings
|
1922
|
-
- default: all numeric attributes
|
1923
|
-
- formerly known as: `numericAttributesToIndex`
|
1924
|
-
|
1925
|
-
List of numeric attributes that can be used as numerical filters.
|
1926
|
-
|
1927
|
-
If not specified, all numeric attributes are automatically indexed and available as numerical filters
|
1928
|
-
(via the [filters](#filters) parameter).
|
1929
|
-
If specified, only attributes explicitly listed are available as numerical filters.
|
1930
|
-
If empty, no numerical filters are allowed.
|
1931
|
-
|
1932
|
-
If you don't need filtering on some of your numerical attributes, you can use `numericAttributesForFiltering` to
|
1933
|
-
speed up the indexing.
|
1934
|
-
|
1935
|
-
If you only need to filter on a numeric value based on equality (i.e. with the operators `=` or `!=`),
|
1936
|
-
you can speed up the indexing by specifying `equalOnly(${attributeName})`.
|
1937
|
-
Other operators will be disabled.
|
1938
|
-
|
1939
|
-
#### allowCompressionOfIntegerArray
|
1940
|
-
|
1941
|
-
- scope: `settings`
|
1942
|
-
- type: boolean
|
1943
|
-
- default: `false`
|
1944
|
-
|
1945
|
-
Enables compression of large integer arrays.
|
1946
|
-
|
1947
|
-
In data-intensive use-cases, we recommended enabling this feature to reach a better compression ratio on arrays
|
1948
|
-
exclusively containing integers (as is typical of lists of user IDs or ACLs).
|
1949
|
-
|
1950
|
-
**Note:** When enabled, integer arrays may be reordered.
|
1951
|
-
|
1952
|
-
## Advanced
|
1953
|
-
|
1954
|
-
#### attributeForDistinct
|
1955
|
-
|
1956
|
-
- scope: `settings`
|
1957
|
-
- type: string
|
1958
|
-
- default: `null`
|
1959
|
-
|
1960
|
-
Name of the de-duplication attribute for the [distinct](#distinct) feature.
|
1961
|
-
|
1962
|
-
#### distinct
|
1963
|
-
|
1964
|
-
- scope: `settings` `search`
|
1965
|
-
- type: integer \| boolean
|
1966
|
-
- default: `0`
|
1967
|
-
|
1968
|
-
Controls de-duplication of results.
|
1969
|
-
|
1970
|
-
A non-zero value enables de-duplication; a zero value disables it.
|
1971
|
-
Booleans are also accepted (though not recommended): false is treated as 0, and true is treated as 1.
|
1972
|
-
|
1973
|
-
**Note:** De-duplication requires a **de-duplication attribute** to be configured via the [attributeForDistinct](#attributefordistinct) index setting.
|
1974
|
-
If not configured, `distinct` will be accepted at query time but silently ignored.
|
1975
|
-
|
1976
|
-
This feature is similar to the SQL `distinct` keyword. When set to N (where N > 0), at most N hits will be returned
|
1977
|
-
with the same value for the de-duplication attribute.
|
1978
|
-
|
1979
|
-
**Example:** If the de-duplication attribute is `show_name` and `distinct` is set to 1, then if several hits have the
|
1980
|
-
same value for `show_name`, only the most relevant one is kept (with respect to the ranking formula); the others are removed.
|
1981
|
-
|
1982
|
-
To get a full understanding of how `distinct` works,
|
1983
|
-
you can have a look at our [Guides](https://www.algolia.com/doc/guides/search/distinct).
|
1984
|
-
|
1985
|
-
#### getRankingInfo
|
1986
|
-
|
1987
|
-
- scope: `search`
|
1988
|
-
- type: boolean
|
1989
|
-
- default: `false`
|
1990
|
-
|
1991
|
-
Enables detailed ranking information.
|
1992
|
-
|
1993
|
-
When true, each hit in the response contains an additional `_rankingInfo` object containing the following fields:
|
1994
|
-
|
1995
|
-
<!-- TODO: Factorize this list with the Search Response Format section. -->
|
1996
|
-
|
1997
|
-
- `nbTypos` (integer): Number of typos encountered when matching the record. Corresponds to the `typos` ranking criterion in the ranking formula.
|
1998
|
-
|
1999
|
-
- `firstMatchedWord` (integer): Position of the most important matched attribute in the attributes to index list. Corresponds to the `attribute` ranking criterion in the ranking formula.
|
2000
|
-
|
2001
|
-
- `proximityDistance` (integer): When the query contains more than one word, the sum of the distances between matched words. Corresponds to the `proximity` criterion in the ranking formula.
|
2002
|
-
|
2003
|
-
- `userScore` (integer): Custom ranking for the object, expressed as a single numerical value. Conceptually, it's what the position of the object would be in the list of all objects sorted by custom ranking. Corresponds to the `custom` criterion in the ranking formula.
|
2004
|
-
|
2005
|
-
- `geoDistance` (integer): Distance between the geo location in the search query and the best matching geo location in the record, divided by the geo precision.
|
2006
|
-
|
2007
|
-
- `geoPrecision` (integer): Precision used when computed the geo distance, in meters. All distances will be floored to a multiple of this precision.
|
2008
|
-
|
2009
|
-
- `nbExactWords` (integer): Number of exactly matched words. If `alternativeAsExact` is set, it may include plurals and/or synonyms.
|
2010
|
-
|
2011
|
-
- `words` (integer): Number of matched words, including prefixes and typos.
|
2012
|
-
|
2013
|
-
- `filters` (integer): *This field is reserved for advanced usage.* It will be zero in most cases.
|
2014
|
-
|
2015
|
-
In addition, the response contains the following additional top-level fields:
|
2016
|
-
|
2017
|
-
- `serverUsed` (string): Actual host name of the server that processed the request. (Our DNS supports automatic failover and load balancing, so this may differ from the host name used in the request.)
|
2018
|
-
|
2019
|
-
- `parsedQuery` (string): The query string that will be searched, after normalization. Normalization includes removing stop words (if [removeStopWords](#removestopwords) is enabled), and transforming portions of the query string into phrase queries (see [advancedSyntax](#advancedsyntax)).
|
2020
|
-
|
2021
|
-
- `timeoutCounts` (boolean): Whether a timeout was hit when computing the facet counts. When `true`, the counts will be interpolated (i.e. approximate). See also `exhaustiveFacetsCount`.
|
2022
|
-
|
2023
|
-
- `timeoutHits` (boolean): Whether a timeout was hit when retrieving the hits. When true, some results may be missing.
|
2024
|
-
|
2025
|
-
#### numericFilters
|
2026
|
-
|
2027
|
-
- scope: `search`
|
2028
|
-
- type: array of strings
|
2029
|
-
- default: `[]`
|
2030
|
-
|
2031
|
-
Filter hits based on values of numeric attributes.
|
2032
|
-
|
2033
|
-
**Note:** The [filters](#filters) parameter provides an easier to use, SQL-like syntax.
|
2034
|
-
We recommend using it instead of `numericFilters`.
|
2035
|
-
|
2036
|
-
Each string represents a filter on a numeric attribute. Two forms are supported:
|
2037
|
-
|
2038
|
-
- **Comparison**: `${attributeName} ${operator} ${operand}` matches all objects where the specified numeric attribute satisfies the numeric condition expressed by the operator and the operand. The operand must be a numeric value. Supported operators are `<`, `<=`, `=`, `!=`, `>=` and `>`, with the same semantics as in virtually all programming languages.
|
2039
|
-
Example: `inStock > 0`.
|
2040
|
-
|
2041
|
-
- **Range**: `${attributeName}:${lowerBound} TO ${upperBound}` matches all objects where the specified numeric
|
2042
|
-
attribute is within the range [`${lowerBound}`, `${upperBound}`] \(inclusive on both ends).
|
2043
|
-
Example: `price: 0 TO 1000`.
|
2044
|
-
|
2045
|
-
If you specify multiple filters, they are interpreted as a conjunction (AND). If you want to use a disjunction (OR),
|
2046
|
-
use a nested array.
|
2047
|
-
|
2048
|
-
Examples:
|
2049
|
-
|
2050
|
-
- `["inStock > 0", "price < 1000"]` translates as `inStock > 0 AND price < 1000`
|
2051
|
-
- `[["inStock > 0", "deliveryDate < 1441755506"], "price < 1000"]` translates as `(inStock > 0 OR deliveryDate < 1441755506) AND price < 1000`
|
2052
|
-
|
2053
|
-
#### tagFilters
|
2054
|
-
|
2055
|
-
- scope: `search`
|
2056
|
-
- type: array of strings
|
2057
|
-
- default: `[]`
|
2058
|
-
|
2059
|
-
Filter hits by tags.
|
2060
|
-
|
2061
|
-
Tags must be contained in a top-level `_tags` attribute of your objects at indexing time.
|
2062
|
-
|
2063
|
-
**Note:** Tags are essentially an implicit facet on the `_tags` attribute.
|
2064
|
-
We therefore recommend that you use facets instead.
|
2065
|
-
See [attributesForFaceting](#attributesforfaceting) and [facets](#facets).
|
2066
|
-
|
2067
|
-
**Note:** The [filters](#filters) parameter provides an easier to use, SQL-like syntax.
|
2068
|
-
We recommend using it instead of `tagFilters`.
|
2069
|
-
|
2070
|
-
Each string represents a given tag value that must be matched.
|
2071
|
-
|
2072
|
-
If you specify multiple tags, they are interpreted as a conjunction (AND). If you want to use a disjunction (OR),
|
2073
|
-
use a nested array.
|
2074
|
-
|
2075
|
-
Examples:
|
2076
|
-
|
2077
|
-
- `["Book", "Movie"]` translates as `Book AND Movie`
|
2078
|
-
- `[["Book", "Movie"], "SciFi"]` translates as `(Book OR Movie) AND SciFi"`
|
2079
|
-
|
2080
|
-
Negation is supported by prefixing the tag value with a minus sign (`-`, a.k.a. dash).
|
2081
|
-
For example: `["tag1", "-tag2"]` translates as `tag1 AND NOT tag2`.
|
2082
|
-
|
2083
|
-
#### analytics
|
2084
|
-
|
2085
|
-
- scope: `search`
|
2086
|
-
- type: boolean
|
2087
|
-
- default: `true`
|
2088
|
-
|
2089
|
-
Whether the current query will be taken into account in the Analytics.
|
2090
|
-
|
2091
|
-
#### analyticsTags
|
2092
|
-
|
2093
|
-
- scope: `search`
|
2094
|
-
- type: array of strings
|
2095
|
-
- default: `[]`
|
2096
|
-
|
2097
|
-
List of tags to apply to the query in the Analytics.
|
2098
|
-
|
2099
|
-
Tags can be used in the Analytics to filter searches.
|
2100
|
-
|
2101
|
-
#### synonyms
|
2102
|
-
|
2103
|
-
- scope: `search`
|
2104
|
-
- type: boolean
|
2105
|
-
- default: `true`
|
2106
|
-
|
2107
|
-
Whether to take into account synonyms defined for the targeted index.
|
2108
|
-
|
2109
|
-
#### replaceSynonymsInHighlight
|
2110
|
-
|
2111
|
-
- scope: `settings` `search`
|
2112
|
-
- type: boolean
|
2113
|
-
- default: `true`
|
2114
|
-
|
2115
|
-
Whether to replace words matched via synonym expansion by the matched synonym in highlight and snippet results.
|
2116
|
-
|
2117
|
-
When true, highlighting and snippeting will use words from the query rather than the original words from the objects.
|
2118
|
-
When false, highlighting and snippeting will always display the original words from the objects.
|
2119
|
-
|
2120
|
-
**Note:** Multiple words can be replaced by a one-word synonym, but not the other way round.
|
2121
|
-
For example, if "NYC" and "New York City" are synonyms, searching for "NYC" will replace "New York City" with "NYC"
|
2122
|
-
in highlights and snippets, but searching for "New York City" will *not* replace "NYC" with "New York City" in
|
2123
|
-
highlights and snippets.
|
2124
|
-
|
2125
|
-
#### placeholders
|
2126
|
-
|
2127
|
-
- scope: `settings`
|
2128
|
-
- type: object of array of words
|
2129
|
-
- default: `{}`
|
2130
|
-
|
2131
|
-
This is an advanced use-case to define a token substitutable by a list of words
|
2132
|
-
without having the original token searchable.
|
2133
|
-
|
2134
|
-
It is defined by a hash associating placeholders to lists of substitutable words.
|
2135
|
-
|
2136
|
-
For example, `"placeholders": { "<streetnumber>": ["1", "2", "3", ..., "9999"]}`
|
2137
|
-
would allow it to be able to match all street numbers. We use the `< >` tag syntax
|
2138
|
-
to define placeholders in an attribute.
|
2139
|
-
|
2140
|
-
For example:
|
2141
|
-
|
2142
|
-
* Push a record with the placeholder:
|
2143
|
-
`{ "name" : "Apple Store", "address" : "<streetnumber> Opera street, Paris" }`.
|
2144
|
-
* Configure the placeholder in your index settings:
|
2145
|
-
`"placeholders": { "<streetnumber>" : ["1", "2", "3", "4", "5", ... ], ... }`.
|
2146
|
-
|
2147
|
-
#### altCorrections
|
2148
|
-
|
2149
|
-
- scope: `settings`
|
2150
|
-
- type: array of objects
|
2151
|
-
- default: `[]`
|
2152
|
-
|
2153
|
-
Specify alternative corrections that you want to consider.
|
2154
|
-
|
2155
|
-
Each alternative correction is described by an object containing three attributes:
|
2156
|
-
|
2157
|
-
* `word` (string): The word to correct.
|
2158
|
-
* `correction` (string): The corrected word.
|
2159
|
-
* `nbTypos` (integer): The number of typos (1 or 2) that will be considered for the ranking algorithm (1 typo is better than 2 typos).
|
2160
|
-
|
2161
|
-
For example:
|
2162
|
-
|
2163
|
-
```
|
2164
|
-
"altCorrections": [
|
2165
|
-
{ "word" : "foot", "correction": "feet", "nbTypos": 1 },
|
2166
|
-
{ "word": "feet", "correction": "foot", "nbTypos": 1 }
|
2167
|
-
]
|
2168
|
-
```
|
2169
|
-
|
2170
|
-
#### minProximity
|
2171
|
-
|
2172
|
-
- scope: `settings` `search`
|
2173
|
-
- type: integer
|
2174
|
-
- default: `1`
|
2175
|
-
|
2176
|
-
Precision of the `proximity` ranking criterion.
|
2177
|
-
|
2178
|
-
By default, the minimum (and best) proximity value between two matching words is 1.
|
2179
|
-
|
2180
|
-
Setting it to 2 (respectively N) would allow 1 (respectively N-1) additional word(s) to be found between two matching words without degrading the proximity ranking value.
|
2181
|
-
|
2182
|
-
**Example:** considering the query *"javascript framework"*, if you set `minProximity` to 2,
|
2183
|
-
two records containing respectively *"JavaScript framework"* and *"JavaScript charting framework"*
|
2184
|
-
will get the same proximity score, even if the latter contains an additional word between the two matching words.
|
2185
|
-
|
2186
|
-
**Note:** The maximum value for `minProximity` is 7. Any higher value will **disable** the `proximity` criterion in the ranking formula.
|
2187
|
-
|
2188
|
-
#### responseFields
|
2189
|
-
|
2190
|
-
- scope: `settings` `search`
|
2191
|
-
- type: array of strings
|
2192
|
-
- default: `*` (all fields)
|
2193
|
-
|
2194
|
-
Choose which fields the response will contain. Applies to search and browse queries.
|
2195
|
-
|
2196
|
-
By default, all fields are returned. If this parameter is specified, only the fields explicitly
|
2197
|
-
listed will be returned, unless `*` is used, in which case all fields are returned.
|
2198
|
-
Specifying an empty list or unknown field names is an error.
|
2199
|
-
|
2200
|
-
This parameter is mainly intended to limit the response size.
|
2201
|
-
For example, in complex queries, echoing of request parameters in the response's `params` field can be undesirable.
|
2202
|
-
|
2203
|
-
List of fields that can be filtered out:
|
2204
|
-
|
2205
|
-
- `aroundLatLng`
|
2206
|
-
- `automaticRadius`
|
2207
|
-
- `exhaustiveFacetsCount`
|
2208
|
-
- `facets`
|
2209
|
-
- `facets_stats`
|
2210
|
-
- `hits`
|
2211
|
-
- `hitsPerPage`
|
2212
|
-
- `index`
|
2213
|
-
- `length`
|
2214
|
-
- `nbHits`
|
2215
|
-
- `nbPages`
|
2216
|
-
- `offset`
|
2217
|
-
- `page`
|
2218
|
-
- `params`
|
2219
|
-
- `processingTimeMS`
|
2220
|
-
- `query`
|
2221
|
-
- `queryAfterRemoval`
|
2222
|
-
|
2223
|
-
List of fields that *cannot* be filtered out:
|
2224
|
-
|
2225
|
-
- `message`
|
2226
|
-
- `warning`
|
2227
|
-
- `cursor`
|
2228
|
-
- `serverUsed`
|
2229
|
-
- `timeoutCounts` (deprecated, please use `exhaustiveFacetsCount` instead)
|
2230
|
-
- `timeoutHits` (deprecated, please use `exhaustiveFacetsCount` instead)
|
2231
|
-
- `parsedQuery`
|
2232
|
-
- all fields triggered by [getRankingInfo](#getrankinginfo)
|
2233
|
-
|
2234
|
-
|
2235
|
-
# Manage Indices
|
2236
|
-
|
2237
|
-
|
2238
|
-
|
2239
|
-
## Create an index
|
2240
|
-
|
2241
|
-
To create an index, you need to perform any indexing operation like:
|
2242
|
-
- set settings
|
2243
|
-
- add object
|
2244
|
-
|
2245
|
-
## List indices - `list_indexes`
|
2246
|
-
|
2247
|
-
You can list all your indices along with their associated information (number of entries, disk size, etc.) with the `list_indexes` method:
|
2248
|
-
|
2249
|
-
```ruby
|
2250
|
-
Algolia.list_indexes
|
2251
|
-
```
|
2252
|
-
|
2253
|
-
## Delete an index - `delete_index`
|
2254
|
-
|
2255
|
-
You can delete an index using its name:
|
2256
|
-
|
2257
|
-
```ruby
|
2258
|
-
index = Algolia::Index.new("contacts")
|
2259
|
-
index.delete_index
|
2260
|
-
```
|
2261
|
-
|
2262
|
-
## Clear an index - `clear_index`
|
2263
|
-
|
2264
|
-
You can delete the index contents without removing settings and index specific API keys by using the `clearIndex` command:
|
2265
|
-
|
2266
|
-
```ruby
|
2267
|
-
index.clear_index
|
2268
|
-
```
|
2269
|
-
|
2270
|
-
## Copy index - `copy_index`
|
2271
|
-
|
2272
|
-
You can copy an existing index using the `copy` command.
|
2273
|
-
|
2274
|
-
**Warning**: The copy command will overwrite the destination index.
|
2275
|
-
|
2276
|
-
```ruby
|
2277
|
-
# Copy MyIndex in MyIndexCopy
|
2278
|
-
puts Algolia.copy_index("MyIndex", "MyIndexCopy")
|
2279
|
-
```
|
2280
|
-
|
2281
|
-
## Move index - `move_index`
|
2282
|
-
|
2283
|
-
In some cases, you may want to totally reindex all your data. In order to keep your existing service
|
2284
|
-
running while re-importing your data we recommend the usage of a temporary index plus an atomical
|
2285
|
-
move using the `move_index` method.
|
2286
|
-
|
2287
|
-
```ruby
|
2288
|
-
# Rename MyNewIndex in MyIndex (and overwrite it)
|
2289
|
-
puts Algolia.move_index("MyNewIndex", "MyIndex")
|
2290
|
-
```
|
2291
|
-
|
2292
|
-
**Note:** The move_index method overrides the destination index, and deletes the temporary one.
|
2293
|
-
In other words, there is no need to call the `clear_index` or `delete_index` methods to clean the temporary index.
|
2294
|
-
It also overrides all the settings of the destination index (except the [replicas](#replicas) parameter that need to not be part of the temporary index settings).
|
2295
|
-
|
2296
|
-
**Recommended steps**
|
2297
|
-
If you want to fully update your index `MyIndex` every night, we recommend the following process:
|
2298
|
-
|
2299
|
-
1. Get settings and synonyms from the old index using [Get settings](#get-settings)
|
2300
|
-
and [Get synonym](#get-synonym).
|
2301
|
-
1. Apply settings and synonyms to the temporary index `MyTmpIndex`, (this will create the `MyTmpIndex` index)
|
2302
|
-
using [Set settings](#set-settings) and [Batch synonyms](#batch-synonyms) ([!] Make sure to remove the [replicas](#replicas) parameter from the settings if it exists.
|
2303
|
-
1. Import your records into a new index using [Add Objects](#add-objects)).
|
2304
|
-
1. Atomically replace the index `MyIndex` with the content and settings of the index `MyTmpIndex`
|
2305
|
-
using the [Move index](#move-index) method.
|
2306
|
-
This will automatically override the old index without any downtime on the search.
|
2307
|
-
|
2308
|
-
You'll end up with only one index called `MyIndex`, that contains the records and settings pushed to `MyTmpIndex`
|
2309
|
-
and the replica-indices that were initially attached to `MyIndex` will be in sync with the new data.
|
2310
|
-
|
2311
|
-
|
2312
|
-
# Api keys
|
2313
|
-
|
2314
|
-
|
2315
|
-
|
2316
|
-
## Overview
|
2317
|
-
|
2318
|
-
When creating your Algolia Account, you'll notice there are 3 different API Keys:
|
2319
|
-
|
2320
|
-
- **Admin API Key** - it provides full control of all your indices.
|
2321
|
-
*The admin API key should always be kept secure;
|
2322
|
-
do NOT give it to anybody; do NOT use it from outside your back-end as it will
|
2323
|
-
allow the person who has it to query/change/delete data*
|
2324
|
-
|
2325
|
-
- **Search-Only API Key** - It allows you to search on every indices.
|
2326
|
-
|
2327
|
-
- **Monitoring API Key** - It allows you to access the [Monitoring API](https://www.algolia.com/doc/rest-api/monitoring)
|
2328
|
-
|
2329
|
-
### Other types of API keys
|
2330
|
-
|
2331
|
-
The *Admin API Key* and *Search-Only API Key* both have really large scope and sometimes you want to give a key to
|
2332
|
-
someone that have restricted permissions, can it be an index, a rate limit, a validity limit, ...
|
2333
|
-
|
2334
|
-
To address those use-cases we have two different type of keys:
|
2335
|
-
|
2336
|
-
- **Secured API Keys**
|
2337
|
-
|
2338
|
-
When you need to restrict the scope of the *Search Key*, we recommend to use *Secured API Key*.
|
2339
|
-
You can generate them on the fly (without any call to the API)
|
2340
|
-
from the *Search Only API Key* or any search *User Key* using the [Generate key](#generate-key) method
|
2341
|
-
|
2342
|
-
- **User API Keys**
|
2343
|
-
|
2344
|
-
If *Secured API Keys* does not meet your requirements, you can make use of *User keys*.
|
2345
|
-
Managing and especially creating those keys requires a call to the API.
|
2346
|
-
|
2347
|
-
We have several methods to manage them:
|
2348
|
-
|
2349
|
-
- [Add user key](#add-user-key)
|
2350
|
-
- [Update user key](#update-user-key)
|
2351
|
-
- [Delete user key](#delete-user-key)
|
2352
|
-
- [List api keys](#list-api-keys)
|
2353
|
-
- [Get key permissions](#get-key-permissions)
|
2354
|
-
|
2355
|
-
## Generate key - `generate_secured_api_key`
|
2356
|
-
|
2357
|
-
When you need to restrict the scope of the *Search Key*, we recommend to use *Secured API Key*.
|
2358
|
-
You can generate a *Secured API Key* from the *Search Only API Key* or any search *User API Key*
|
2359
|
-
|
2360
|
-
There is a few things to know about *Secured API Keys*
|
2361
|
-
- They always need to be generated **on your backend** using one of our API Client
|
2362
|
-
- You can generate them on the fly (without any call to the API)
|
2363
|
-
- They will not appear on the dashboard as they are generated without any call to the API
|
2364
|
-
- The key you use to generate it **needs to become private** and you should not use it in your frontend.
|
2365
|
-
- The generated secured API key **will inherit any restriction from the search key it has been generated from**
|
2366
|
-
|
2367
|
-
You can then use the key in your frontend code
|
2368
|
-
|
2369
|
-
```js
|
2370
|
-
var client = algoliasearch('YourApplicationID', 'YourPublicAPIKey');
|
2371
|
-
|
2372
|
-
var index = client.initIndex('indexName')
|
2373
|
-
|
2374
|
-
index.search('something', function(err, content) {
|
2375
|
-
if (err) {
|
2376
|
-
console.error(err);
|
2377
|
-
return;
|
2378
|
-
}
|
2379
|
-
|
2380
|
-
console.log(content);
|
2381
|
-
});
|
2382
|
-
```
|
2383
|
-
|
2384
|
-
#### Filters
|
2385
|
-
|
2386
|
-
Every filter set in the API key will always be applied. On top of that [filters](#filters) can be applied
|
2387
|
-
in the query parameters.
|
2388
|
-
|
2389
|
-
```ruby
|
2390
|
-
# generate a public API key for user 42. Here, records are tagged with:
|
2391
|
-
# - 'user_XXXX' if they are visible by user XXXX
|
2392
|
-
public_key = Algolia.generate_secured_api_key 'YourSearchOnlyApiKey', {'filters'=> '_tags:user_42'}
|
2393
|
-
```
|
2394
|
-
|
2395
|
-
**Warning**:
|
2396
|
-
|
2397
|
-
If you set filters in the key `groups:admin`, and `groups:press OR groups:visitors` in the query parameters,
|
2398
|
-
this will be equivalent to `groups:admin AND (groups:press OR groups:visitors)`
|
2399
|
-
|
2400
|
-
##### Having one API Key per User
|
2401
|
-
|
2402
|
-
One of the usage of secured API keys, is to have allow users to see only part of an index, when this index
|
2403
|
-
contains the data of all users.
|
2404
|
-
In that case, you can tag all records with their associated `user_id` in order to add a `user_id=42` filter when
|
2405
|
-
generating the *Secured API Key* to retrieve only what a user is tagged in.
|
2406
|
-
|
2407
|
-
**Warning**
|
2408
|
-
|
2409
|
-
If you're generating *Secured API Keys* using the [JavaScript client](http://github.com/algolia/algoliasearch-client-javascript) in your frontend,
|
2410
|
-
it will result in a security breach since the user is able to modify the filters you've set
|
2411
|
-
by modifying the code from the browser.
|
2412
|
-
|
2413
|
-
#### Valid Until
|
2414
|
-
|
2415
|
-
You can set a Unix timestamp used to define the expiration date of the API key
|
2416
|
-
|
2417
|
-
```ruby
|
2418
|
-
# generate a public API key that is valid for 1 hour:
|
2419
|
-
valid_until = Time.now.to_i + 3600
|
2420
|
-
public_key = Algolia.generate_secured_api_key 'YourSearchOnlyApiKey', {'validUntil'=> valid_until}
|
2421
|
-
```
|
2422
|
-
|
2423
|
-
#### Index Restriction
|
2424
|
-
|
2425
|
-
You can restrict the key to a list of index names allowed for the secured API key
|
2426
|
-
|
2427
|
-
```ruby
|
2428
|
-
# generate a public API key that is restricted to 'index1' and 'index2':
|
2429
|
-
public_key = Algolia.generate_secured_api_key 'YourSearchOnlyApiKey', {'restrictIndices'=> 'index1,index2'}
|
2430
|
-
```
|
2431
|
-
|
2432
|
-
#### Rate Limiting
|
2433
|
-
|
2434
|
-
If you want to rate limit a secured API Key, the API key you generate the secured api key from need to be rate-limited.
|
2435
|
-
You can do that either via the dashboard or via the API using the
|
2436
|
-
[Add user key](#add-user-key) or [Update user key](#update-user-key) method
|
2437
|
-
|
2438
|
-
##### User Rate Limiting
|
2439
|
-
|
2440
|
-
By default the rate limits will only use the `IP`.
|
2441
|
-
|
2442
|
-
This can be an issue when several of your end users are using the same IP.
|
2443
|
-
To avoid that, you can set a `userToken` query parameter when generating the key.
|
2444
|
-
|
2445
|
-
When set, a unique user will be identified by his `IP + user_token` instead of only by his `IP`.
|
2446
|
-
|
2447
|
-
This allows you to restrict a single user to performing a maximum of `N` API calls per hour,
|
2448
|
-
even if he shares his `IP` with another user.
|
2449
|
-
|
2450
|
-
```ruby
|
2451
|
-
# generate a public API key for user 42. Here, records are tagged with:
|
2452
|
-
# - 'user_XXXX' if they are visible by user XXXX
|
2453
|
-
public_key = Algolia.generate_secured_api_key 'YourSearchOnlyApiKey', {'filters'=> '_tags:user_42', 'userToken'=> 'user_42'}
|
2454
|
-
```
|
2455
|
-
|
2456
|
-
#### Network restriction
|
2457
|
-
|
2458
|
-
For more protection against API key leaking and reuse you can restrict the key to be valid only from specific IPv4 networks
|
2459
|
-
|
2460
|
-
```ruby
|
2461
|
-
# generate a public API key that is restricted to '192.168.1.0/24':
|
2462
|
-
public_key = Algolia.generate_secured_api_key 'YourSearchOnlyApiKey', {'restrictSources'=> '192.168.1.0/24'}
|
2463
|
-
```
|
2464
|
-
|
2465
|
-
|
2466
|
-
# Synonyms
|
2467
|
-
|
2468
|
-
|
2469
|
-
|
2470
|
-
## Save synonym - `save_synonym`
|
2471
|
-
|
2472
|
-
This method saves a single synonym record into the index.
|
2473
|
-
|
2474
|
-
In this example, we specify true to forward the creation to replica indices.
|
2475
|
-
By default the behavior is to save only on the specified index.
|
2476
|
-
|
2477
|
-
```ruby
|
2478
|
-
index.save_synonym('a-unique-identifier', {
|
2479
|
-
:objectID => 'a-unique-identifier',
|
2480
|
-
:type => 'synonym',
|
2481
|
-
:synonyms => ['car', 'vehicle', 'auto']
|
2482
|
-
}, true)
|
2483
|
-
```
|
2484
|
-
|
2485
|
-
## Batch synonyms - `batch_synonyms`
|
2486
|
-
|
2487
|
-
Use the batch method to create a large number of synonyms at once,
|
2488
|
-
forward them to replica indices if desired,
|
2489
|
-
and optionally replace all existing synonyms
|
2490
|
-
on the index with the content of the batch using the replaceExistingSynonyms parameter.
|
2491
|
-
|
2492
|
-
You should always use replaceExistingSynonyms to atomically replace all synonyms
|
2493
|
-
on a production index. This is the only way to ensure the index always
|
2494
|
-
has a full list of synonyms to use during the indexing of the new list.
|
2495
|
-
|
2496
|
-
```ruby
|
2497
|
-
# Batch synonyms, with replica forwarding and atomic replacement of existing synonyms
|
2498
|
-
index.batch_synonyms([{
|
2499
|
-
:objectID => 'a-unique-identifier',
|
2500
|
-
:type => 'synonym',
|
2501
|
-
:synonyms => ['car', 'vehicle', 'auto']
|
2502
|
-
}, {
|
2503
|
-
:objectID => 'another-unique-identifier',
|
2504
|
-
:type => 'synonym',
|
2505
|
-
:synonyms => ['street', 'st']
|
2506
|
-
}], true, true)
|
2507
|
-
```
|
2508
|
-
|
2509
|
-
## Editing Synonyms
|
2510
|
-
|
2511
|
-
Updating the value of a specific synonym record is the same as creating one.
|
2512
|
-
Make sure you specify the same objectID used to create the record and the synonyms
|
2513
|
-
will be updated.
|
2514
|
-
When updating multiple synonyms in a batch call (but not all synonyms),
|
2515
|
-
make sure you set replaceExistingSynonyms to false (or leave it out,
|
2516
|
-
false is the default value).
|
2517
|
-
Otherwise, the entire synonym list will be replaced only partially with the records
|
2518
|
-
in the batch update.
|
2519
|
-
|
2520
|
-
## Delete synonym - `delete_synonym`
|
2521
|
-
|
2522
|
-
Use the normal index delete method to delete synonyms,
|
2523
|
-
specifying the objectID of the synonym record you want to delete.
|
2524
|
-
Forward the deletion to replica indices by setting the forwardToReplicas parameter to true.
|
2525
|
-
|
2526
|
-
```ruby
|
2527
|
-
# Delete and forward to replicas
|
2528
|
-
index.delete_synonym('a-unique-identifier', true)
|
2529
|
-
```
|
2530
|
-
|
2531
|
-
## Clear all synonyms - `clear_synonyms`
|
2532
|
-
|
2533
|
-
This is a convenience method to delete all synonyms at once.
|
2534
|
-
It should not be used on a production index to then push a new list of synonyms:
|
2535
|
-
there would be a short period of time during which the index would have no synonyms
|
2536
|
-
at all.
|
2537
|
-
|
2538
|
-
To atomically replace all synonyms of an index,
|
2539
|
-
use the batch method with the replaceExistingSynonyms parameter set to true.
|
2540
|
-
|
2541
|
-
```ruby
|
2542
|
-
# Clear synonyms and forward to replicas
|
2543
|
-
index.clear_synonyms(true)
|
2544
|
-
```
|
2545
|
-
|
2546
|
-
## Get synonym - `get_synonym`
|
2547
|
-
|
2548
|
-
Search for synonym records by their objectID or by the text they contain.
|
2549
|
-
Both methods are covered here.
|
2550
|
-
|
2551
|
-
```ruby
|
2552
|
-
synonym = index.get_synonym('a-unique-identifier')
|
2553
|
-
```
|
2554
|
-
|
2555
|
-
## Search synonyms - `search_synonyms`
|
2556
|
-
|
2557
|
-
Search for synonym records similar to how you’d search normally.
|
2558
|
-
|
2559
|
-
Accepted search parameters:
|
2560
|
-
- query: the actual search query to find synonyms. Use an empty query to browse all the synonyms of an index.
|
2561
|
-
- type: restrict the search to a specific type of synonym. Use an empty string to search all types (default behavior). Multiple types can be specified using a comma-separated list or an array.
|
2562
|
-
- page: the page to fetch when browsing through several pages of results. This value is zero-based.
|
2563
|
-
hitsPerPage: the number of synonyms to return for each call. The default value is 100.
|
2564
|
-
|
2565
|
-
```ruby
|
2566
|
-
# Searching for "street" in synonyms and one-way synonyms; fetch the second page with 10 hits per page
|
2567
|
-
results = index.search_synonyms('street', {
|
2568
|
-
:type => ['synonym', 'oneWaySynonym'],
|
2569
|
-
:page => 1,
|
2570
|
-
:hitsPerPage => 10
|
2571
|
-
})
|
2572
|
-
```
|
2573
|
-
|
2574
|
-
|
2575
|
-
# Advanced
|
2576
|
-
|
2577
|
-
|
2578
|
-
|
2579
|
-
## Custom batch - `batch`
|
2580
|
-
|
2581
|
-
You may want to perform multiple operations with one API call to reduce latency.
|
2582
|
-
|
2583
|
-
If you have one index per user, you may want to perform a batch operations across several indices.
|
2584
|
-
We expose a method to perform this type of batch:
|
2585
|
-
|
2586
|
-
```ruby
|
2587
|
-
res = client.batch([
|
2588
|
-
{"action"=> "addObject", "indexName"=> "index1", "body": {"firstname" => "Jimmie",
|
2589
|
-
"lastname" => "Barninger"}},
|
2590
|
-
{"action"=> "addObject", "indexName"=> "index2", "body": {"firstname" => "Warren",
|
2591
|
-
"lastname" => "Speach"}}])
|
2592
|
-
```
|
2593
|
-
|
2594
|
-
The attribute **action** can have these values:
|
2595
|
-
|
2596
|
-
- addObject
|
2597
|
-
- updateObject
|
2598
|
-
- partialUpdateObject
|
2599
|
-
- partialUpdateObjectNoCreate
|
2600
|
-
- deleteObject
|
2601
|
-
|
2602
|
-
## Backup / Export an index - `browse`
|
2603
|
-
|
2604
|
-
The `search` method cannot return more than 1,000 results. If you need to
|
2605
|
-
retrieve all the content of your index (for backup, SEO purposes or for running
|
2606
|
-
a script on it), you should use the `browse` method instead. This method lets
|
2607
|
-
you retrieve objects beyond the 1,000 limit.
|
2608
|
-
|
2609
|
-
This method is optimized for speed. To make it fast, distinct, typo-tolerance,
|
2610
|
-
word proximity, geo distance and number of matched words are disabled. Results
|
2611
|
-
are still returned ranked by attributes and custom ranking.
|
2612
|
-
|
2613
|
-
Ruby has a nice browse method that hides the cursor, so no need to talk about it
|
2614
|
-
It will return a `cursor` alongside your data, that you can then use to retrieve
|
2615
|
-
the next chunk of your records.
|
2616
|
-
|
2617
|
-
You can specify custom parameters (like `page` or `hitsPerPage`) on your first
|
2618
|
-
`browse` call, and these parameters will then be included in the `cursor`. Note
|
2619
|
-
that it is not possible to access records beyond the 1,000th on the first call.
|
2620
|
-
|
2621
|
-
#### Response Format
|
2622
|
-
|
2623
|
-
##### Sample
|
2624
|
-
|
2625
|
-
```json
|
2626
|
-
{
|
2627
|
-
"hits": [
|
2628
|
-
{
|
2629
|
-
"firstname": "Jimmie",
|
2630
|
-
"lastname": "Barninger",
|
2631
|
-
"objectID": "433"
|
2632
|
-
}
|
2633
|
-
],
|
2634
|
-
"processingTimeMS": 7,
|
2635
|
-
"query": "",
|
2636
|
-
"params": "filters=level%3D20",
|
2637
|
-
"cursor": "ARJmaWx0ZXJzPWxldmVsJTNEMjABARoGODA4OTIzvwgAgICAgICAgICAAQ=="
|
2638
|
-
}
|
2639
|
-
```
|
2640
|
-
|
2641
|
-
##### Fields
|
2642
|
-
|
2643
|
-
- `cursor` (string, optional): A cursor to retrieve the next chunk of data. If absent, it means that the end of the index has been reached.
|
2644
|
-
- `query` (string): Query text used to filter the results.
|
2645
|
-
- `params` (string, URL-encoded): Search parameters used to filter the results.
|
2646
|
-
- `processingTimeMS` (integer): Time that the server took to process the request, in milliseconds. *Note: This does not include network time.*
|
2647
|
-
|
2648
|
-
The following fields are provided for convenience purposes, and **only when the browse is not filtered**:
|
2649
|
-
|
2650
|
-
- `nbHits` (integer): Number of objects in the index.
|
2651
|
-
- `page` (integer): Index of the current page (zero-based).
|
2652
|
-
- `hitsPerPage` (integer): Maximum number of hits returned per page.
|
2653
|
-
- `nbPages` (integer): Number of pages corresponding to the number of hits. Basically, `ceil(nbHits / hitsPerPage)`.
|
2654
|
-
|
2655
|
-
#### Example
|
2656
|
-
|
2657
|
-
```ruby
|
2658
|
-
# Iterate with a filter over the index
|
2659
|
-
index.browse() do |hit|
|
2660
|
-
# Do something
|
2661
|
-
end
|
2662
|
-
```
|
2663
|
-
|
2664
|
-
## List api keys - `list_api_keys`
|
2665
|
-
|
2666
|
-
To list existing keys, you can use:
|
2667
|
-
|
2668
|
-
```ruby
|
2669
|
-
# Lists global API Keys
|
2670
|
-
Algolia.list_user_keys
|
2671
|
-
# Lists API Keys that can access only to this index
|
2672
|
-
index.list_user_keys
|
2673
|
-
```
|
2674
|
-
|
2675
|
-
Each key is defined by a set of permissions that specify the authorized actions. The different permissions are:
|
2676
|
-
|
2677
|
-
* **search**: Allowed to search.
|
2678
|
-
* **browse**: Allowed to retrieve all index contents via the browse API.
|
2679
|
-
* **addObject**: Allowed to add/update an object in the index.
|
2680
|
-
* **deleteObject**: Allowed to delete an existing object.
|
2681
|
-
* **deleteIndex**: Allowed to delete index content.
|
2682
|
-
* **settings**: allows to get index settings.
|
2683
|
-
* **editSettings**: Allowed to change index settings.
|
2684
|
-
* **analytics**: Allowed to retrieve analytics through the analytics API.
|
2685
|
-
* **listIndexes**: Allowed to list all accessible indexes.
|
2686
|
-
|
2687
|
-
## Add user key - `add_user_key`
|
2688
|
-
|
2689
|
-
To create API keys:
|
2690
|
-
|
2691
|
-
```ruby
|
2692
|
-
# Creates a new global API key that can only perform search actions
|
2693
|
-
res = Algolia.add_user_key(["search"])
|
2694
|
-
puts res['key']
|
2695
|
-
# Creates a new API key that can only perform search action on this index
|
2696
|
-
res = index.add_user_key(["search"])
|
2697
|
-
puts res['key']
|
2698
|
-
```
|
2699
|
-
|
2700
|
-
You can also create an API Key with advanced settings:
|
2701
|
-
|
2702
|
-
##### validity
|
2703
|
-
|
2704
|
-
Add a validity period. The key will be valid for a specific period of time (in seconds).
|
2705
|
-
|
2706
|
-
##### maxQueriesPerIPPerHour
|
2707
|
-
|
2708
|
-
Specify the maximum number of API calls allowed from an IP address per hour. Each time an API call is performed with this key, a check is performed. If the IP at the source of the call did more than this number of calls in the last hour, a 403 code is returned. Defaults to 0 (no rate limit). This parameter can be used to protect you from attempts at retrieving your entire index contents by massively querying the index.
|
2709
|
-
|
2710
|
-
|
2711
|
-
|
2712
|
-
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.
|
2713
|
-
|
2714
|
-
##### maxHitsPerQuery
|
2715
|
-
|
2716
|
-
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 index contents by massively querying the index.
|
2717
|
-
|
2718
|
-
##### indexes
|
2719
|
-
|
2720
|
-
Specify the list of targeted indices. You can target all indices starting with a prefix or ending with a suffix using the '\*' character. For example, "dev\_\*" matches all indices starting with "dev\_" and "\*\_dev" matches all indices ending with "\_dev". Defaults to all indices if empty or blank.
|
2721
|
-
|
2722
|
-
##### referers
|
2723
|
-
|
2724
|
-
Specify the list of referers. You can target all referers starting with a prefix, ending with a suffix using the '\*' character. For example, "https://algolia.com/\*" matches all referers starting with "https://algolia.com/" and "\*.algolia.com" matches all referers ending with ".algolia.com". If you want to allow the domain algolia.com you can use "\*algolia.com/\*". Defaults to all referers if empty or blank.
|
2725
|
-
|
2726
|
-
##### queryParameters
|
2727
|
-
|
2728
|
-
Specify the list of query parameters. You can force the query parameters for a query using the url string format (param1=X¶m2=Y...).
|
2729
|
-
|
2730
|
-
##### description
|
2731
|
-
|
2732
|
-
Specify a description to describe where the key is used.
|
2733
|
-
|
2734
|
-
```ruby
|
2735
|
-
# Creates a new global API key that is valid for 300 seconds
|
2736
|
-
res = Algolia.add_user_key(["search"], 300)
|
2737
|
-
puts res['key']
|
2738
|
-
# Creates a new index specific API key:
|
2739
|
-
# - valid for 300 seconds
|
2740
|
-
# - rate limit of 100 calls per hour per IP
|
2741
|
-
# - maximum of 20 hits
|
2742
|
-
# - valid on 'my_index1' and 'my_index2'
|
2743
|
-
|
2744
|
-
params = {
|
2745
|
-
:validity => 300,
|
2746
|
-
:maxQueriesPerIPPerHour => 100,
|
2747
|
-
:maxHitsPerQuery => 20,
|
2748
|
-
:indexes => ['my_index1', 'my_index2'],
|
2749
|
-
:referers => ['algolia.com/*'],
|
2750
|
-
:queryParameters => 'typoTolerance=strict&ignorePlurals=false',
|
2751
|
-
:description => 'Limited search only API key for algolia.com'
|
2752
|
-
}
|
2753
|
-
|
2754
|
-
res = Algolia.add_user_key(params)
|
2755
|
-
puts res['key']
|
2756
|
-
```
|
2757
|
-
|
2758
|
-
## Update user key - `update_user_key`
|
2759
|
-
|
2760
|
-
To update the permissions of an existing key:
|
2761
|
-
|
2762
|
-
```ruby
|
2763
|
-
# Update an existing global API key that is valid for 300 seconds
|
2764
|
-
res = Algolia.update_user_key("myAPIKey", ["search"], 300)
|
2765
|
-
puts res['key']
|
2766
|
-
# Update an existing index specific API key:
|
2767
|
-
# - valid for 300 seconds
|
2768
|
-
# - rate limit of 100 calls per hour per IP
|
2769
|
-
# - maximum of 20 hits
|
2770
|
-
# - valid on 'my_index1' and 'my_index2'
|
2771
|
-
res = index.update_user_key("myAPIKey", ["search"], 300, 100, 20, ['my_index1', 'my_index2'])
|
2772
|
-
puts res['key']
|
2773
|
-
```
|
2774
|
-
|
2775
|
-
To get the permissions of a given key:
|
2776
|
-
|
2777
|
-
```ruby
|
2778
|
-
# Gets the rights of a global key
|
2779
|
-
Algolia.get_user_key("f420238212c54dcfad07ea0aa6d5c45f")
|
2780
|
-
# Gets the rights of an index specific key
|
2781
|
-
index.get_user_key("71671c38001bf3ac857bc82052485107")
|
2782
|
-
```
|
2783
|
-
|
2784
|
-
## Delete user key - `delete_user_key`
|
2785
|
-
|
2786
|
-
To delete an existing key:
|
2787
|
-
|
2788
|
-
```ruby
|
2789
|
-
# Deletes a global key
|
2790
|
-
Algolia.delete_user_key("f420238212c54dcfad07ea0aa6d5c45f")
|
2791
|
-
# Deletes an index specific key
|
2792
|
-
index.delete_user_key("71671c38001bf3ac857bc82052485107")
|
2793
|
-
```
|
2794
|
-
|
2795
|
-
## Get key permissions - `get_user_key_acl`
|
2796
|
-
|
2797
|
-
To get the permissions of a given key:
|
2798
|
-
|
2799
|
-
```ruby
|
2800
|
-
# Gets the rights of a global key
|
2801
|
-
Algolia.get_user_key("f420238212c54dcfad07ea0aa6d5c45f")
|
2802
|
-
# Gets the rights of an index specific key
|
2803
|
-
index.get_user_key("71671c38001bf3ac857bc82052485107")
|
2804
|
-
```
|
2805
|
-
|
2806
|
-
## Get latest logs - `get_logs`
|
2807
|
-
|
2808
|
-
You can retrieve the latest logs via this API. Each log entry contains:
|
2809
|
-
|
2810
|
-
* Timestamp in ISO-8601 format
|
2811
|
-
* Client IP
|
2812
|
-
* Request Headers (API Key is obfuscated)
|
2813
|
-
* Request URL
|
2814
|
-
* Request method
|
2815
|
-
* Request body
|
2816
|
-
* Answer HTTP code
|
2817
|
-
* Answer body
|
2818
|
-
* SHA1 ID of entry
|
2819
|
-
|
2820
|
-
You can retrieve the logs of your last 1,000 API calls and browse them using the offset/length parameters:
|
2821
|
-
|
2822
|
-
#### offset
|
2823
|
-
|
2824
|
-
Specify the first entry to retrieve (0-based, 0 is the most recent log entry). Defaults to 0.
|
2825
|
-
|
2826
|
-
#### length
|
2827
|
-
|
2828
|
-
Specify the maximum number of entries to retrieve starting at the offset. Defaults to 10. Maximum allowed value: 1,000.
|
2829
|
-
|
2830
|
-
#### onlyErrors
|
2831
|
-
|
2832
|
-
Retrieve only logs with an HTTP code different than 200 or 201. (deprecated)
|
2833
|
-
|
2834
|
-
#### type
|
2835
|
-
|
2836
|
-
Specify the type of logs to retrieve:
|
2837
|
-
|
2838
|
-
* `query`: Retrieve only the queries.
|
2839
|
-
* `build`: Retrieve only the build operations.
|
2840
|
-
* `error`: Retrieve only the errors (same as `onlyErrors` parameters).
|
2841
|
-
|
2842
|
-
```ruby
|
2843
|
-
# Get last 10 log entries
|
2844
|
-
puts Algolia.get_logs.to_json
|
2845
|
-
# Get last 100 log entries
|
2846
|
-
puts Algolia.get_logs(0, 100).to_json
|
2847
|
-
# Get last 100 errors
|
2848
|
-
puts Algolia.get_logs(0, 100, true).to_json
|
2849
|
-
```
|
2850
|
-
|
2851
|
-
## REST API
|
2852
|
-
|
2853
|
-
We've developed API clients for the most common programming languages and platforms.
|
2854
|
-
These clients are advanced wrappers on top of our REST API itself and have been made
|
2855
|
-
in order to help you integrating the service within your apps:
|
2856
|
-
for both indexing and search.
|
2857
|
-
|
2858
|
-
Everything that can be done using the REST API can be done using those clients.
|
2859
|
-
|
2860
|
-
The REST API lets your interact directly with Algolia platforms from anything that can send an HTTP request
|
2861
|
-
[Go to the REST API doc](https://algolia.com/doc/rest)
|
2862
|
-
|
2863
|
-
|
2864
|
-
# Mocking
|
2865
|
-
|
2866
|
-
|
2867
|
-
|
2868
|
-
## Webmock
|
2869
|
-
|
2870
|
-
For testing purposes, you may want to mock Algolia's API calls. We provide a [WebMock](https://github.com/bblimke/webmock) configuration that you can use including `algolia/webmock`:
|
2871
|
-
|
2872
|
-
```ruby
|
2873
|
-
require 'algolia/webmock'
|
2874
|
-
|
2875
|
-
describe 'With a mocked client' do
|
2876
|
-
|
2877
|
-
before(:each) do
|
2878
|
-
WebMock.enable!
|
2879
|
-
end
|
2880
|
-
|
2881
|
-
it "shouldn't perform any API calls here" do
|
2882
|
-
index = Algolia::Index.new("friends")
|
2883
|
-
index.add_object!({ :name => "John Doe", :email => "john@doe.org" })
|
2884
|
-
index.search('').should == {"hits"=>[{"objectID"=>42}], "page"=>1, "hitsPerPage"=>1} # mocked
|
2885
|
-
index.clear_index
|
2886
|
-
index.delete_index
|
2887
|
-
end
|
2888
|
-
|
2889
|
-
after(:each) do
|
2890
|
-
WebMock.disable!
|
2891
|
-
end
|
2892
|
-
|
2893
|
-
end
|
2894
|
-
```
|
2895
158
|
|
2896
159
|
|