#community-help

Resolving Short Word Precedence Issue in Typesense Search

TLDR Jake experienced partial short word matches in a typesense search taking precedence over exact matches. Kishore Nallan recommended adjusting the query order, using 'exhaustive_search', and setting 'max_candidates' to optimize results.

Powered by Struct AI

1

14
2mo
Solved
Join the chat
Jul 13, 2023 (2 months ago)
Jake
Photo of md5-b1e18c0615ca3ca625d5acbac79fa4fe
Jake
08:08 AM
Is anyone having issues with short words and partial matches taking precedence over exact?
e.g.
typesense is set to search over 3 fields; query_by: productCode, productTitle, productDescription
no other additionalSearchParamters are set.
Searching for: pen will always find partial results in the productCode field before exact results in productTitle or productDescription
What is even worse is that results increase if productCode is removed, with productCode it returns 12 results, without it returns 1686
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
08:12 AM
Can you post the first matching document for this query pen?
Jake
Photo of md5-b1e18c0615ca3ca625d5acbac79fa4fe
Jake
08:15 AM
with productCode
Image 1 for with productCodeImage 2 for with productCode
08:16
Jake
08:16 AM
without
Image 1 for withoutImage 2 for without
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
08:18 AM
When you place productCode ahead in the query_by list you are influencing its weight in ranking. Try placing it last.
Jake
Photo of md5-b1e18c0615ca3ca625d5acbac79fa4fe
Jake
08:18 AM
it still shouldnt take a partial ahead of exact though should it and it shouldnt alter the number of results?
08:20
Jake
08:20 AM
i.e. results shouldnt go up with less fields, less fields to search over should mean less results?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
08:23 AM
When a given prefix can match multiple words and when we cannot exhaustively go through all words, we pick the words that are most likely to produce results. This candidate list can change based on the fields used. For e.g. with productCode, the engine is picking a word like pen2567 which won't exist in other fields.

You can set max_candidates: 100 to make the engine look for more candidates.
Jake
Photo of md5-b1e18c0615ca3ca625d5acbac79fa4fe
Jake
08:28 AM
ive tried adding exhaustive_search=true which is giving better results, 2107 for pen and correctly now matching exact first
08:29
Jake
08:29 AM
and removing productCode, the number of results goes does to 1985 which is expected
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
08:30 AM
Exhaustive search also considers all typos and will try to drop tokens from the query also. With Max candidates it will not try to drop tokens or consider typos exhaustively.
Jake
Photo of md5-b1e18c0615ca3ca625d5acbac79fa4fe
Jake
08:32 AM
ok, thanks a lot, let me play around a bit more and see what gives the best results

1

08:35
Jake
08:35 AM
max_candidates:100 had little effect, had to set to 200 to not get productCode being picked up first
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
08:39 AM
You could also try disabling prefix on product code field