Skip to content

Commit 3ee79aa

Browse files
author
maxiloc
authored
Merge pull request #76 from algoliareadmebot/master
docs(README): automatic update
2 parents cd3e8a4 + 2a7973e commit 3ee79aa

File tree

1 file changed

+196
-16
lines changed

1 file changed

+196
-16
lines changed

README.md

Lines changed: 196 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ Check our [online guides](https://www.algolia.com/doc):
126126

127127

128128

129+
129130
## Getting Started
130131

131132
### Install
@@ -251,14 +252,18 @@ function searchCallback(err, content) {
251252

252253
To perform a search, you only need to initialize the index and perform a call to the search function.
253254

254-
The search query allows only to retrieve 1000 hits, if you need to retrieve more than 1000 hits for seo, you can use [Backup / Retrieve all index content](#backup--export-an-index)
255+
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 / Retrieve all index content](#backup--export-an-index).
255256

256257
```python
257258
index = client.init_index("contacts")
258259
res = index.search("query string")
259260
res = index.search("query string", { "attributesToRetrieve": "firstname,lastname", "hitsPerPage": 20})
260261
```
261262

263+
### Search Response Format
264+
265+
#### Sample
266+
262267
The server response will look like:
263268

264269
```json
@@ -294,7 +299,110 @@ The server response will look like:
294299
}
295300
```
296301

297-
You can use the following optional arguments:
302+
#### Fields
303+
304+
- `hits` (array): The hits returned by the search, sorted according to the ranking formula.
305+
306+
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:
307+
308+
- `_highlightResult` (object, optional): Highlighted attributes. *Note: Only returned when [`attributesToHighlight`](#attributestohighlight) is non-empty.*
309+
310+
- `${attribute_name}` (object): Highlighting for one attribute.
311+
312+
- `value` (string): Markup text with occurrences highlighted. The tags used for highlighting are specified via [`highlightPreTag`](#highlightpretag) and [`highlightPostTag`](#highlightposttag).
313+
314+
- `matchLevel` (string, enum) = {`none` | `partial` | `full`}: Indicates how well the attribute matched the search query.
315+
316+
- `matchedWords` (array): List of words *from the query* that matched the object.
317+
318+
- `fullyHighlighted` (boolean): Whether the entire attribute value is highlighted.
319+
320+
- `_snippetResult` (object, optional): Snippeted attributes. *Note: Only returned when [`attributesToSnippet`](#attributestosnippet) is non-empty.*
321+
322+
- `${attribute_name}` (object): Snippeting for the corresponding attribute.
323+
324+
- `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).
325+
326+
- `matchLevel` (string, enum) = {`none` | `partial` | `full`}: Indicates how well the attribute matched the search query.
327+
328+
- `_rankingInfo` (object, optional): Ranking information. *Note: Only returned when [`getRankingInfo`](#getrankinginfo) is `true`.*
329+
330+
- `nbTypos` (integer): Number of typos encountered when matching the record. Corresponds to the `typos` ranking criterion in the ranking formula.
331+
332+
- `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.
333+
334+
- `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.
335+
336+
- `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.
337+
338+
- `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.
339+
340+
- `geoPrecision` (integer): Precision used when computed the geo distance, in meters. All distances will be floored to a multiple of this precision.
341+
342+
- `nbExactWords` (integer): Number of exactly matched words. If `alternativeAsExact` is set, it may include plurals and/or synonyms.
343+
344+
- `words` (integer): Number of matched words, including prefixes and typos.
345+
346+
- `filters` (integer): *This field is reserved for advanced usage.* It will be zero in most cases.
347+
348+
- `_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.
349+
350+
- `nbHits` (integer): Number of hits that the search query matched.
351+
352+
- `page` (integer): Index of the current page (zero-based). See the [`page`](#page) search parameter.
353+
354+
- `hitsPerPage` (integer): Maximum number of hits returned per page. See the [`hitsPerPage`](#hitsperpage) search parameter.
355+
356+
- `nbPages` (integer): Number of pages corresponding to the number of hits. Basically, `ceil(nbHits / hitsPerPage)`.
357+
358+
- `processingTimeMS` (integer): Time that the server took to process the request, in milliseconds. *Note: This does not include network time.*
359+
360+
- `query` (string): An echo of the query text. See the [`query`](#query) search parameter.
361+
362+
- `queryAfterRemoval` (string, optional): *Note: Only returned when [`removeWordsIfNoResults`](#removewordsifnoresults) is set.* 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.
363+
364+
- `params` (string, URL-encoded): An echo of all search parameters.
365+
366+
- `message` (string, optional): Used to return warnings about the query.
367+
368+
- `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.
369+
370+
- `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.**
371+
372+
When [`getRankingInfo`](#getrankinginfo) is set to `true`, the following additional fields are returned:
373+
374+
- `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.)
375+
376+
- `parsedQuery` (string): The query string that will be searched, after normalization.
377+
378+
- `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`.
379+
380+
- `timeoutHits` (boolean): Whether a timeout was hit when retrieving the hits. When true, some results may be missing.
381+
382+
... and ranking information is also added to each of the hits (see above).
383+
384+
When [`facets`](#facets) is non-empty, the following additional fields are returned:
385+
386+
- `facets` (object): Maps each facet name to the corresponding facet counts:
387+
388+
- `${facet_name}` (object): Facet counts for the corresponding facet name:
389+
390+
- `${facet_value}` (integer): Count for this facet value.
391+
392+
- `facets_stats` (object, optional): *Note: Only returned when at least one of the returned facets contains numerical values.* Statistics for numerical facets:
393+
394+
- `${facet_name}` (object): The statistics for a given facet:
395+
396+
- `min` (integer | float): The minimum value in the result set.
397+
398+
- `max` (integer | float): The maximum value in the result set.
399+
400+
- `avg` (integer | float): The average facet value in the result set.
401+
402+
- `sum` (integer | float): The sum of all values in the result set.
403+
404+
- `exhaustiveFacetsCount` (boolean): Whether the counts are exhaustive (`true`) or approximate (`false`). *Note: When using [`distinct`](#distinct), the facet counts cannot be exhaustive.*
405+
298406

299407
### Search Parameters
300408

@@ -350,7 +458,7 @@ Parameters that can also be used in a setSettings also have the `indexing` [scop
350458

351459
**Advanced**
352460
- [distinct](#distinct) `settings`, `search`
353-
- [rankingInfo](#rankinginfo) `search`
461+
- [getRankingInfo](#getrankinginfo) `search`
354462
- [numericFilters (deprecated)](#numericfilters-deprecated) `search`
355463
- [tagFilters (deprecated)](#tagfilters-deprecated) `search`
356464
- [facetFilters (deprecated)](#facetfilters-deprecated) `search`
@@ -703,7 +811,7 @@ They are three scopes:
703811
**Advanced**
704812
- [attributeForDistinct](#attributefordistinct) `settings`
705813
- [distinct](#distinct) `settings`, `search`
706-
- [rankingInfo](#rankinginfo) `search`
814+
- [getRankingInfo](#getrankinginfo) `search`
707815
- [numericAttributesToIndex](#numericattributestoindex) `settings`
708816
- [allowCompressionOfIntegerArray](#allowcompressionofintegerarray) `settings`
709817
- [numericFilters (deprecated)](#numericfilters-deprecated) `search`
@@ -1419,7 +1527,7 @@ To get a full understanding of how `Distinct` works,
14191527
you can have a look at our [guide on distinct](https://www.algolia.com/doc/search/distinct).
14201528

14211529

1422-
#### rankingInfo
1530+
#### getRankingInfo
14231531

14241532
- scope: `search`
14251533
- type: `boolean`
@@ -1619,28 +1727,48 @@ index.clear_index()
16191727

16201728
### Copy index - `copy_index`
16211729

1622-
You can easily copy or rename an existing index using the `copy` and `move` commands.
1623-
**Note**: Move and copy commands overwrite the destination index.
1730+
You can copy an existing index using the `copy` command.
1731+
**Note**: The copy command will overwrite the destination index.
16241732

16251733
```python
1626-
# Rename MyIndex in MyIndexNewName
1627-
print client.move_index("MyIndex", "MyIndexNewName")
16281734
# Copy MyIndex in MyIndexCopy
16291735
print client.copy_index("MyIndex", "MyIndexCopy")
16301736
```
16311737

16321738

16331739
### Move index - `move_index`
16341740

1635-
The move command is particularly useful if you want to update a big index atomically from one version to another. For example, if you recreate your index `MyIndex` each night from a database by batch, you only need to:
1636-
1. Import your database into a new index using [batches](#batch-writes). Let's call this new index `MyNewIndex`.
1637-
1. Rename `MyNewIndex` to `MyIndex` using the move command. This will automatically override the old index and new queries will be served on the new one.
1741+
In some cases, you may want to totally reindex all your data. In order to keep your existing service
1742+
running while re-importing your data we recommend the usage of a temporary index plus an atomical
1743+
move using the move_index method.
16381744

16391745
```python
16401746
# Rename MyNewIndex in MyIndex (and overwrite it)
16411747
print client.move_index("MyNewIndex", "MyIndex")
16421748
```
16431749

1750+
**Note**:
1751+
1752+
The move_index method will overwrite the destination index, and delete the temporary index.
1753+
1754+
**Warning**
1755+
1756+
The move_index operation will override all settings of the destination,
1757+
There is one exception for the [slaves](#slaves) parameter which is not impacted.
1758+
1759+
For example, if you want to fully update your index `MyIndex` every night, we recommend the following process:
1760+
1. Get settings and synonyms from the old index using [Get settings](#get-settings---get_settings)
1761+
and Get synonym - `get_synonym`.
1762+
1. Apply settings and synonyms to the temporary index `MyTmpIndex`, (this will create the `MyTmpIndex` index)
1763+
using [Set settings](#set-settings) and Batch synonyms - `batch_synonyms`
1764+
(make sure to remove the [slaves](#slaves) parameter from the settings if it exists).
1765+
1. Import your records into a new index using [Add objects](#add-objects---add_objects).
1766+
1. Atomically replace the index `MyIndex` with the content and settings of the index `MyTmpIndex`
1767+
using the move_index method.
1768+
This will automatically override the old index without any downtime on the search.
1769+
1. You'll end up with only one index called `MyIndex`, that contains the records and settings pushed to `MyTmpIndex`
1770+
and the slave-indices that were initially attached to `MyIndex` will be in sync with the new data.
1771+
16441772

16451773

16461774

@@ -1891,7 +2019,48 @@ You can specify custom parameters (like `page` or `hitsPerPage`) on your first
18912019
`browse` call, and these parameters will then be included in the `cursor`. Note
18922020
that it is not possible to access records beyond the 1,000th on the first call.
18932021

1894-
Example:
2022+
#### Response Format
2023+
2024+
##### Sample
2025+
2026+
```json
2027+
{
2028+
"hits": [
2029+
{
2030+
"firstname": "Jimmie",
2031+
"lastname": "Barninger",
2032+
"objectID": "433"
2033+
}
2034+
],
2035+
"processingTimeMS": 7,
2036+
"query": "",
2037+
"params": "filters=level%3D20",
2038+
"cursor": "ARJmaWx0ZXJzPWxldmVsJTNEMjABARoGODA4OTIzvwgAgICAgICAgICAAQ=="
2039+
}
2040+
```
2041+
2042+
##### Fields
2043+
2044+
- `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.
2045+
2046+
- `query` (string): Query text used to filter the results.
2047+
2048+
- `params` (string, URL-encoded): Search parameters used to filter the results.
2049+
2050+
- `processingTimeMS` (integer): Time that the server took to process the request, in milliseconds. *Note: This does not include network time.*
2051+
2052+
The following fields are provided for convenience purposes, and **only when the browse is not filtered**:
2053+
2054+
- `nbHits` (integer): Number of objects in the index.
2055+
2056+
- `page` (integer): Index of the current page (zero-based).
2057+
2058+
- `hitsPerPage` (integer): Maximum number of hits returned per page.
2059+
2060+
- `nbPages` (integer): Number of pages corresponding to the number of hits. Basically, `ceil(nbHits / hitsPerPage)`.
2061+
2062+
2063+
#### Example
18952064

18962065
```python
18972066
# Iterate with a filter over the index
@@ -2022,7 +2191,7 @@ You can also create an API Key with advanced settings:
20222191
</div>
20232192
</td>
20242193
<td class='client-readme-param-content'>
2025-
<p>Specify the list of referers. You can target all referers starting with a prefix or ending with a suffix using the &#39;*&#39; character. For example, &quot;algolia.com/*&quot; matches all referers starting with &quot;algolia.com/&quot; and &quot;*.algolia.com&quot; matches all referers ending with &quot;.algolia.com&quot;. Defaults to all referers if empty or blank.</p>
2194+
<p>Specify the list of referers. You can target all referers starting with a prefix, ending with a suffix using the &#39;*&#39; character. For example, &quot;<a href="https://algolia.com/%5C*">https://algolia.com/\*</a>&quot; matches all referers starting with &quot;<a href="https://algolia.com/">https://algolia.com/</a>&quot; and &quot;*.algolia.com&quot; matches all referers ending with &quot;.algolia.com&quot;. If you want to allow the domain algolia.com you can use &quot;*algolia.com/*&quot;. Defaults to all referers if empty or blank.</p>
20262195

20272196
</td>
20282197
</tr>
@@ -2134,12 +2303,23 @@ results = self.client.multiple_queries([{"indexName" : "categories", "query" : m
21342303
print results["results"]
21352304
```
21362305

2137-
The resulting JSON answer contains a ```results``` array storing the underlying queries answers. The answers order is the same than the requests order.
2138-
21392306
You can specify a `strategy` parameter to optimize your multiple queries:
21402307
- `none`: Execute the sequence of queries until the end.
21412308
- `stopIfEnoughMatches`: Execute the sequence of queries until the number of hits is reached by the sum of hits.
21422309

2310+
#### Response
2311+
2312+
The resulting JSON contains the following fields:
2313+
2314+
- `results` (array): The results for each request, in the order they were submitted. The contents are the same as in [Search in an index](#search-in-an-index---search).
2315+
2316+
Each result also includes the following additional fields:
2317+
2318+
- `index` (string): The name of the targeted index.
2319+
2320+
- `processed` (boolean, optional): *Note: Only returned when `strategy` is `stopIfEnoughmatches`.* Whether the query was processed.
2321+
2322+
21432323

21442324

21452325
### Get Logs - `get_logs`

0 commit comments

Comments
 (0)