Api clients / Ruby / V1 / Methods

Search Synonyms | Ruby API Client V1 (Deprecated)

This version of the Ruby API client has been deprecated in favor of the latest version of the Ruby API client.

Required API Key: any key with the editSettings ACL
Method signature
index.search_synonyms(
  String query,
  {
    type: String,
    page: Integer,
    hitsPerPage: Integer
  }
)

About this method

Get all synonyms that match a query.

Examples

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:

  • synonym
  • oneWaySynonym
  • altCorrection1 or altCorrection2
  • placeholder
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

In this section we document the JSON response returned by the API. Each language will encapsulate this response inside objects specific to the language and/or the implementation. So the actual type in your language might differ from what is documented.

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
}
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

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:

  • synonym
  • oneWaySynonym
  • altCorrection1 or altCorrection2
  • placeholder
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 word.

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 placeholder.

hits ➔ _highlightResult

value
string

Markup text with occurrences highlighted. The tags used for highlighting are specified via highlightPreTag and highlightPostTag.

matchLevel
string

Indicates how well the attribute matched the search query. Can be:

  • none (0)
  • partial some)
  • full (all)

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.

Did you find this page helpful?