#community-help

Resolving Issues with Synonyms and Typo Tolerance in a Document

TLDR Slavik was having trouble with synonyms and typo tolerance while searching for documents. Jason suggested using one-way vs multi-way synonyms and configuring typo-tolerance parameters.

Powered by Struct AI
+12
10
4mo
Solved
Join the chat
May 15, 2023 (4 months ago)
Slavik
Photo of md5-ca6495d5be926db80e09aabf066f4b8b
Slavik
04:10 PM
Hello!
May I ask you for your help, please?

I have a document whose name field value is Volkswagen e-Golf 35 kWh (2017 - 2020).
I added the synonyms to Volkswagen (screenshot 1) as vw, VW, vewe. But when I am trying to search by vw or VW - there are no documents :(

cURL:
curl '' \
  -H 'authority: ' \
  ...
  --data-raw '{"searches":[{"q":"vw","query_by":"name","sort_by":"name:asc","highlight_full_fields":"name","collection":"X","page":1,"per_page":8}]}' \
  --compressed

I am using the alias for my index and searching inside it.
The name field structure is: { name: 'name', type: 'string', facet: false, sort: true }
Image 1 for Hello!<br>May I ask you for your help, please?<br><br>I have a document whose name field value is <code>Volkswagen e-Golf 35 kWh (2017 - 2020)</code>.<br>I added the synonyms to <code>Volkswagen</code> (screenshot 1) as <code>vw, VW, vewe</code>. But when I am trying to search by <code>vw</code> or <code>VW</code> - there are no documents :(<br><br>cURL:<br><pre><code>curl '<https://xxx.typesense.net/multi_search?x-typesense-api-key=API-KEY>' \
  -H 'authority: <http://xxx.typesense.net|xxx.typesense.net>' \
  ...
  --data-raw '{"searches":[{"q":"vw","query_by":"name","sort_by":"name:asc","highlight_full_fields":"name","collection":"X","page":1,"per_page":8}]}' \
  --compressed</code></pre><br>I am using the alias for my index and searching inside it.<br>The <code>name</code> field structure is: <code>{ name: &#x27;name&#x27;, type: &#x27;string&#x27;, facet: false, sort: true }</code>
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
04:16 PM
With your current settings in the screenshot, where you’ve set Volkswagen as the root, only searching for Volkswagen will return results with that word, and also the words you’ve mentioned under Synonyms
04:16
Jason
04:16 PM
Here’s a description of what one-way vs multi-way synonyms mean (first paragraph): https://typesense.org/docs/0.24.1/api/synonyms.html#synonyms
Slavik
Photo of md5-ca6495d5be926db80e09aabf066f4b8b
Slavik
04:17 PM
Yes. Sorry, found an issue.
Adding vw as a root and Volkswagen as a synonym resolved an issue.
+11
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
04:19 PM
Side note: Typesense is case in-sensitive, so you don’t have to add vw and VW, just lower case is sufficient
Slavik
Photo of md5-ca6495d5be926db80e09aabf066f4b8b
Slavik
04:22 PM
Thank you!
also, another question.

I have a document whose name field value is BMW 225xe (2019 - 2022).

When I am trying to search by bmw -> it works fine.
When I am trying to search by bwm -> nothing. The same for bm .
04:23
Slavik
04:23 PM
  --data-raw '{"searches":[{"q":"Bwm","query_by":"name","sort_by":"name:asc","highlight_full_fields":"name","collection":"x","page":1,"per_page":8}]}' \
  --compressed
04:24
Slavik
04:24 PM
Is it possible to resolve on a query side on improving Typo-Tolerance parameters or only by synonyms?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
04:28 PM
By default typo-tolerance only kicks-in when a search term is more 4 characters, but you can configure this using min_len_1typo and min_len_2typo

https://typesense.org/docs/0.24.1/api/search.html#typo-tolerance-parameters
Slavik
Photo of md5-ca6495d5be926db80e09aabf066f4b8b
Slavik
04:29 PM
Thank you, Jason!
+11