> ## Documentation Index
> Fetch the complete documentation index at: https://algolia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Search synonyms

> Get all synonyms that match a query.

export const Legacy = ({title, href}) => {
  return <Note>

    This page documents an earlier version of the API client.
    For the latest version, see <a href={href}>{title}</a>.

    </Note>;
};

<Legacy title="Search for synonyms" href="/doc/libraries/sdk/methods/search/search-synonyms" />

**Required ACL:** `settings`

## Examples

<CodeGroup>
  ```cs C# theme={"system"}
  // Searching for "street" in synonyms and one-way synonyms;
  // fetch the second page with 10 hits per page

  var result = index.SearchSynonyms(
    new SynonymQuery ("street")
    {
      Type = "synonym, oneWaySynonym"
      Page = 1,
      HitsPerPage = 10
    }
  );
  ```

  ```go Go theme={"system"}
  // Searching for "street" in synonyms and one-way synonyms;
  // fetch the second page with 10 hits per page

  opts := []interface{}{
  	opt.Type("synonym", "oneWaySynonym"),
  	opt.Page(1),
  	opt.HitsPerPage(10),
  }

  res, err := index.SearchSynonyms("street", opts...)
  synonyms := res.Synonyms()
  ```

  ```java Java theme={"system"}
  // Searching for "street" in synonyms and one-way synonyms;
  // fetch the second page with 10 hits per page
  SynonymQuery query =  new SynonymQuery("street")
      .setTypes(Arrays.asList("synonym", "one_way"))
      .setPage(1)
      .setHitsPerPage(10);

  SearchResult<Synonym> results = index.searchSynonyms(query);

  // Async
  SearchResult<Synonym> results = index.searchSynonyms(query);
  ```

  ```js JavaScript theme={"system"}
  // Searching for "street" in synonyms and one-way synonyms;
  // fetch the second page with 10 hits per page

  index
    .searchSynonyms("street", {
      type: "synonym, oneWaySynonym",
      page: 1,
      hitsPerPage: 10,
    })
    .then(({ hits }) => {
      console.log(hits);
    });
  ```

  ```kotlin Kotlin theme={"system"}
  val query = SynonymQuery(
      query = "street",
      hitsPerPage = 10,
      page = 1,
      types = listOf(SynonymType.MultiWay, SynonymType.OneWay)
  )

  index.searchSynonyms(query)
  ```

  ```php PHP theme={"system"}
  // 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
  ]);
  ```

  ```python Python theme={"system"}
  # Searching for "street" in synonyms and one-way synonyms; fetch the second page with 10 hits per page
  results = index.search_synonyms(
      "street", {"type": "synonym, oneWaySynonym", "page": 1, "hitsPerPage": 10}
  )
  ```

  ```ruby Ruby theme={"system"}
  # Searching for "street" in synonyms and one-way synonyms;
  # fetch the second page with 10 hits per page
  results = index.search_synonyms(
    "street",
    {
      type: "synonym,oneWaySynonym",
      page: 1,
      hitsPerPage: 10
    }
  )
  ```

  ```scala Scala theme={"system"}
  // Searching for "street" in synonyms and one-way synonyms;
  // fetch the second page with 10 hits per page

  var results = client.execute {
    search synonyms in index "index_name" query QuerySynonyms(
      query = "street",
      types = Some(Seq(SynonymType.synonym, SynonymType.oneWaySynonym)),
      page = Some(1),
      hitsPerPage = Some(10)
    )
  }
  ```

  ```swift Swift theme={"system"}
  // Searching for "street" in synonyms and one-way synonyms;
  // fetch the second page with 10 hits per page
  var query = SynonymQuery()
  query.query = "street"
  query.hitsPerPage = 10
  query.page = 1
  query.synonymTypes = [.multiWay, .oneWay]

  index.searchSynonyms(query) { result in
    if case .success(let response) = result {
      print("Response: \(response)")
    }
  }
  ```
</CodeGroup>

## Parameters

<ParamField body="query" type="string" required>
  The search query to find synonyms.
  Use an empty query to browse all the synonyms of an index.
</ParamField>

<ParamField body="hitsPerPage" type="string" default={20}>
  The number of synonyms to return for each call.
</ParamField>

<ParamField body="page" type="integer" default={0}>
  The page to fetch when browsing through several pages of results.
  This value is zero-based.
</ParamField>

<ParamField body="type" type="string | string[]">
  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`
</ParamField>

## Response

<ResponseField name="hits" type="list">
  A list of matching synonyms.
  Each hit contains
  the synonym object and a `_highlightResult` attribute with the highlighted synonym.

  <Expandable>
    <ResponseField name="corrections" type="string[]">
      List of corrections.
      (For synonym types `altCorrection1` or `altCorrection2`).
    </ResponseField>

    <ResponseField name="input" type="string">
      A word used as the basis for synonyms.
      (For synonym type `oneWaySynonym`).
    </ResponseField>

    <ResponseField name="objectID" type="string">
      Object ID of the matched synonym.
    </ResponseField>

    <ResponseField name="placeholder" type="string">
      A word used as the basis for replacements.
      (For synonym type `placeholder`).
    </ResponseField>

    <ResponseField name="replacements" type="string[]">
      List of replacements for the placeholder.
      (For synonym type `placeholder`).
    </ResponseField>

    <ResponseField name="synonyms" type="string[]">
      List of synonyms.
      (For synonym types `synonym` or `oneWaySynonym`).
    </ResponseField>

    <ResponseField name="type" type="string">
      Synonym type. One of:

      * `synonym`
      * `oneWaySynonym`
      * `altCorrection1`
      * `altCorrection2`
      * `placeholder`
    </ResponseField>

    <ResponseField name="word" type="string">
      A word used as the basis for corrections.
      (For synonym types `altCorrection1` or `altCorrection2`).
    </ResponseField>

    <ResponseField name="_highlightResult" type="object">
      Highlighted synonym object.

      <Expandable>
        <ResponseField name="fullyHighlighted" type="boolean">
          Whether the entire attribute value is highlighted.
        </ResponseField>

        <ResponseField name="matchedWords" type="string[]">
          List of query words that matched the object.
        </ResponseField>

        <ResponseField name="matchLevel" type="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.
        </ResponseField>

        <ResponseField name="value" type="string">
          Markup text with occurrences highlighted.
          The tags used for highlighting are specified
          via [`highlightPreTag`](/doc/api-reference/api-parameters/highlightPreTag) and [`highlightPostTag`](/doc/api-reference/api-parameters/highlightPostTag).
        </ResponseField>
      </Expandable>
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="nbHits" type="integer">
  Number of hits.
</ResponseField>

### Response as JSON

This section shows the JSON response returned by the API.
Each API client wraps this response in language-specific objects, so the structure may vary.
To view the response, use the `getLogs` method.
Don't rely on the order of properties—JSON objects don't preserve key order.

```jsonc JSON icon=braces theme={"system"}
{
  "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
}
```
