Synonyms Feature Not Working as Expected in Typesense Cloud
TLDR Vamshi is experiencing issues with the synonyms feature in Typesense Cloud, as it doesn't return the expected results. Kishore Nallan tries to provide support, but the issue remains unresolved.
Mar 16, 2023 (7 months ago)
Vamshi
01:09 PMWe are customers of typesense cloud and we are using it to power our search. We have recently started to leverage the synonyms feature of typesense, but it is not working as we expect. We have created a synonym with root as
bull tshirt
and the synonym as blue tshirt
, the same can be seen in the screen shot below (which I took from the synonyms page)So my understanding is that when I search for
bull tshirt
I should get results for blue t-shirt as well. But when I query for bull tshirt
I am getting zero results, but when I query for blue tshirt
I am getting 25 results. Here are the actual queries:In [161]: bull_tshirt_results = make_query("bull tshirt", False, False, False, False)
Making the query: {
"q": "bull tshirt",
"query_by": "searchText0,searchText1,searchText2",
"group_by": "productId",
"group_limit": 1,
"filter_by": "gender:=[`Men`]",
"per_page": 100,
"prefix": "false,false,false",
"split_join_tokens": "off"
}
In [162]: bull_tshirt_results["found"]
Out[162]: 0
In [163]: blue_tshirt_results = make_query("blue tshirt", False, False, False, False)
Making the query: {
"q": "blue tshirt",
"query_by": "searchText0,searchText1,searchText2",
"group_by": "productId",
"group_limit": 1,
"filter_by": "gender:=[`Men`]",
"per_page": 100,
"prefix": "false,false,false",
"split_join_tokens": "off"
}
In [164]: blue_tshirt_results["found"]
Out[164]: 25
As you can see, the search with
bull tshirt
doesn't return anything, where as blue tshirt
returns 25 results.Here's the
make_query
function if it helpsdef make_query(query: str, split: bool = False, inflix: bool = False, prefix: bool = False, disable_typo_tolerance=False):
payload = {
"q": query,
"query_by": "searchText0,searchText1,searchText2",
"group_by": "productId",
"group_limit": 1,
"filter_by": "gender:=[`Men`]",
"per_page": 100
}
if not prefix:
payload["prefix"] = "false,false,false"
if inflix:
payload["infix"] = "always,always,always"
if not split:
payload["split_join_tokens"] = "off"
if disable_typo_tolerance:
payload["num_typos"] = 0
payload["typo_tokens_threshold"] = 0
print(f"Making the query: {json.dumps(payload, indent=2)}")
resp = ts_client.collections["product_variants"].documents.search(payload)
return resp
Any help is very appreciated. Thanks!
Kishore Nallan
01:25 PMKishore Nallan
01:29 PMMar 17, 2023 (7 months ago)
Vamshi
04:44 AMIn [173]: bull_tshirt_results_restricted = make_query_restricted("bull tshirt", False, False, False, True)
Making the query: {
"q": "bull tshirt",
"query_by": "searchText2",
"group_limit": 1,
"filter_by": "gender:=[`Men`]",
"per_page": 100,
"prefix": "false",
"split_join_tokens": "off",
"num_typos": 0,
"typo_tokens_threshold": 0
}
In [174]: bull_tshirt_results_restricted["found"]
Out[174]: 0
In [175]: blue_tshirt_results_restricted = make_query_restricted("blue tshirt", False, False, False, True)
Making the query: {
"q": "blue tshirt",
"query_by": "searchText2",
"group_limit": 1,
"filter_by": "gender:=[`Men`]",
"per_page": 100,
"prefix": "false",
"split_join_tokens": "off",
"num_typos": 0,
"typo_tokens_threshold": 0
}
In [176]: blue_tshirt_results_restricted["found"]
Out[176]: 93
(The results are higher because of the removal of group by)
Kishore Nallan
04:46 AMVamshi
04:52 AMVamshi
05:11 AMBut in the actual collection, they aren't working. I have double checked that the synonyms actually existed, so I am stumped. Is it possible that some other curation override or synonym is affecting this?
Kishore Nallan
05:19 AMVamshi
08:44 AMTypesense
Indexed 2776 threads (79% resolved)
Similar Threads
Phrase Search Relevancy and Weights Fix
Jan reported an issue with phrase search relevancy using Typesense Instantsearch Adapter. The problem occurred when searching phrases with double quotes. The team identified the issue to be related to weights and implemented a fix, improving the search results.
Resolving Typesense Result Issue in Document Collection Queries
Mike was encountering errors when searching for specific query in their Typesense document collection. Jason suggested it may be due to the `drop_tokens_threshold` setting. There was a misunderstanding but after further explanation from Jason, Mike understood and decided to continue the conversation via email.
Querying with Not-in in Typesense
Masahiro inquired about using not-in queries in Typesense. Kishore Nallan explained how to conduct such queries by using the "-" operator in the query string, and assisted Masahiro with issues stemming from a high number of exclusion tokens. The problem was eventually resolved by switching to the `multi_search` endpoint.
Querying and Indexing Multiple Elements Issues
Krish queried fields with multiple elements, which Kishore Nallan suggested checking `drop_tokens_threshold`. Krish wished to force OR mode for token, but Kishore Nallan admitted the feature was missing. Krish was able to resolve the issue with url encoding.
Troubleshooting Typesense Setup and Understanding Facets and Keywords
Demitri encountered errors when exploring Typesense for the first time. Jason guided them through troubleshooting and discussed facets, keyword settings, and widget configurations. Helin shared a Python demo app and its source code to help Demitri with their project.