#community-help

Typesense Query and Matching Explained.

TLDR David queried about Typesense's query weights and matching. Jason clarified that Typesense prioritizes exact matches in the same field, which can be changed with 'prioritize_exact_matches: false'.

Powered by Struct AI

1

Oct 28, 2022 (14 months ago)
David
Photo of md5-07c4f1bfa85fc4a2759ba7302f0b86da
David
12:58 PM
Hi! I have a question about weighing. Or more I need an explanation 🙂 I have these two documents
{
  id: 1
  productName: "Stripe",
  variantName: "Throw, Black / White"
},
{
  id: 2
  productName: "Monster",
  variantName: "Throw, Ochre / Off-white Stripe"
}

I've set my params to prioritise productName over variantName, like this query_by: 'sku,productName,variantName,designer,tags', query_by_weights: '5,4,3,1,2'. When I search stripe throw, id 2 comes before id 1, even through id 1 is an exact hit of the more prioritised field. Why? id 2 has two exact matches in its variantName, but I still don't want that to "win" as the productName match is more important for me.

Images in 🧵
01:03
David
01:03 PM
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
03:18 PM
By default, Typesense considers a field that matches all search terms exactly, to be the most relevant. You can disable this behavior by setting prioritize_exact_matches: false
David
Photo of md5-07c4f1bfa85fc4a2759ba7302f0b86da
David
03:29 PM
But this matches ”stripe throw” exactly, on both of them, right? Just that on one document it matches on two separate fields
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
04:13 PM
We should probably improve the name of that parameter, it should really be “prioritize_exact_match when all matches appear in the same field”. It essentially overrides weights when all keywords exist in the same field
David
Photo of md5-07c4f1bfa85fc4a2759ba7302f0b86da
David
05:17 PM
Got it. Thanks for explaining!

1