#community-help

Excluding Specific Documents in Typesense Results

TLDR Alexander asked how to exclude specific documents in Typesense search results, and Jason suggested using the hidden_hits search parameter and multi_search for large lists.

Powered by Struct AI
Mar 26, 2023 (8 months ago)
Alexander
Photo of md5-8ac455f6d302407f03def4c775778b28
Alexander
12:22 AM
I had an interesting discussion lately. Let's say the following scenario:
• A user uses a few filters and search for some documents.
• The user is allowed to i.e. "ignore" documents in the results to not see those again.
How would I tell Typesense to not include these results - depending on the user searching?

A few options I researched:
• Long queries: Simply use a filter, but use very long queries if many results are excluded
• Overrides: Have a list of excluded documents per user which will still be a long query, just at a different time as I have not found a way to "add conditions" instead of creating full lists
How would you guys implement this, especially for large amounts of excludes? 🙂
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
01:49 AM
There’s a search parameter called hidden_hits that you can use to exclude specific document IDs for a search query.
01:50
Jason
01:50 AM
That would be the most appropriate for this use case. You could use multi_search to allow for a large list of document IDs
Alexander
Photo of md5-8ac455f6d302407f03def4c775778b28
Alexander
01:59 AM
Thank you for your answer! How large can such a query become? Could I hide say 1000 IDs? is that even a good idea? I wanted to do this on Typesense's end to be able to still use pagination.
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
02:02 AM
Yeah 1000 IDs should be fine
02:03
Jason
02:03 AM
Typesense will take care of pagination as well