Search synonyms
This is documentation for v3 of the PHP API clients, which is not the latest version. To see the documentation for the latest version, see PHP v4.
This is documentation for v2 of the Ruby API clients, which is not the latest version. To see the documentation for the latest version, see Ruby v3.
This is documentation for v4 of the JavaScript API clients, which is not the latest version. To see the documentation for the latest version, see JavaScript v5.
This is documentation for v3 of the Python API clients, which is not the latest version. To see the documentation for the latest version, see Python v4.
This is documentation for v8 of the Swift API clients, which is not the latest version. To see the documentation for the latest version, see Swift v9.
This is documentation for v2 of the Kotlin API clients, which is not the latest version. To see the documentation for the latest version, see Kotlin v3.
This is documentation for v6 of the C# API clients, which is not the latest version. To see the documentation for the latest version, see C# v7.
This is documentation for v3 of the Java API clients, which is not the latest version. To see the documentation for the latest version, see Java v4.
This is documentation for v3 of the Go API clients, which is not the latest version. To see the documentation for the latest version, see Go v4.
This is documentation for v1 of the Scala API clients, which is not the latest version. To see the documentation for the latest version, see Scala v2.
Required API Key:
any key with the
settings
ACL
$index->searchSynonyms(string query) $index->searchSynonyms(string query, [ 'page' => integer, 'type' => string, 'hitsPerPage' => integer, ])
You’re currently reading the JavaScript API client v4 documentation. Check the migration guide to learn how to upgrade from v3 to v4. You can still access the v3 documentation.
You’re currently reading the Ruby API client v2 documentation. Check the migration guide to learn how to upgrade from v1 to v2. You can still access the v1 documentation.
About this method
Get all synonyms that match a query.
Examples
Read the Algolia CLI documentation for more information.
1
2
3
4
5
6
7
8
// Searching for "street" in synonyms and one-way synonyms;
// fetch the second page with 10 hits per page
$results = $index->searchSynonyms("street", [
'type' => 'synonym, oneWaySynonym',
'page' => 1,
'hitsPerPage' => 10
]);
Parameters
query
|
type: string
Required
The search query to find synonyms. Use an empty query to browse all the synonyms of an index. |
type
|
type: string|list
default: ""
Optional
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. The allowed types are:
|
page
|
type: integer
default: 0
Optional
The page to fetch when browsing through several pages of results. This value is zero-based. |
hitsPerPage
|
type: string
default: 100
Required
The number of synonyms to return for each call. |
Response
This section shows the JSON response returned by the API.
Each API client encapsulates this response inside objects specific to the programming language,
so that the actual response might be different.
You can view the response by using the getLogs
method.
Don’t rely on the order of attributes in the response, as JSON doesn’t guarantee the ordering of keys in objects.
JSON format
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
{
"hits":[
{
"type":"synonym",
"synonyms": [
"car",
"vehicle"
],
"objectID":"1513249039298",
"_highlightResult":{
"type":{
"value":"synonym",
"matchLevel":"none",
"matchedWords": []
},
"synonyms":[
{
"value":"<b>c<\/b>ar",
"matchLevel":"full",
"fullyHighlighted":false,
"matchedWords": [
"c"
]
},
{
"value":"vehicle",
"matchLevel":"none",
"matchedWords": []
}
]
}
}
],
"nbHits":1
}
Field | Description |
---|---|
hits
|
list
A list of hits, where each hit contains the synonym object and a _highlightResult attribute (which contains the highlighted synonym object). |
nbHits
|
integer
Number of hits. |
hits ➔ synonym object
Field | Description |
---|---|
objectID
|
string
Required for only some languages
Must contain the same value as the objectId above. |
type
|
string
Required
There are 4 synonym types. The parameter can be one of the following values:
|
synonyms
|
list
Required if type=synonym or type=oneWaySynonym
A list of synonyms |
input
|
string
Required if type=oneWaySynonym
Defines the synonym. A word or expression, used as the basis for the array of synonyms. |
word
|
string
Required if type=altCorrection1 or type=altCorrection2
A single word, used as the basis for the below array of corrections. |
corrections
|
list
Required if type=altCorrection1 or type=altCorrection2
An list of corrections of the |
placeholder
|
string
Required if type=placeholder
A single word, used as the basis for the below array of replacements. |
replacements
|
list
Required if type=placeholder
An list of replacements of the |
hits ➔ _highlightResult
Field | Description |
---|---|
value
|
string
Markup text with occurrences highlighted.
The tags used for highlighting are specified
via |
matchLevel
|
string
Indicates how well the attribute matched the search query. Can be:
The matching relates to the words in the query string not in the searched text of the records. By “meaningful” we mean: if stop words are removed, they are not taken into account. So if you match everything but stop words (and removeStopWords is enabled), then it’s a full match. This has nothing to do with prefixes, plurals, synonyms, or typos. No matter how “accurately” a word matches, if it matches, it counts as one. |
matchedWords
|
list
List of words from the query that matched the object. |
fullyHighlighted
|
boolean
Whether the entire attribute value is highlighted. |