#random

Querying TypeSense with Different Search String Orders

TLDR Jesper needed explanation on the difference in TypeSense search results for "X Y" and "Y X". Kishore Nallan clarified that Typesense treats the last word as a prefix query, explaining the discrepancy.

Powered by Struct AI
Jul 11, 2023 (5 months ago)
Jesper
Photo of md5-94c93df7325e8fde185c76c659656ee9
Jesper
11:57 AM
Hello everyone,

We're currently exploring the usability of TypeSense for several new websites we plan to build in 2024. As part of our testing process, we're experimenting with different aspects of the platform.

During my investigation, I came across a specific issue that I haven't been able to find an answer to in the documentation. It's possible that I'm simply not interpreting the documentation correctly.

The problem we've encountered involves a discrepancy in search results when searching for "X Y" versus searching for "Y X". I'm curious about how TypeSense weighs the input of the search string and would like to know where I can find more information on this topic.

Based on my observations, it seems that when there are multiple words in the search query, the second word might even contribute to a negative score.

I appreciate any assistance or guidance you can provide.

Best regards,
Jesper
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
12:11 PM
👋 By default Typesense treats the last word in the query as a prefix query. So in X Y Y is searched as a prefix and in Y X X is searched as a prefix. This can lead to the results being different. If you don't want this behavior you can set prefix: false
Jesper
Photo of md5-94c93df7325e8fde185c76c659656ee9
Jesper
12:29 PM
Thanks 🙂 ❤️