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
6
6mo
Solved
Mar 26, 2023 (6 months ago)
Alexander
Alexander
12:22 AMI 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? 🙂
• 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
Jason
01:49 AMThere’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 AMThat would be the most appropriate for this use case. You could use multi_search to allow for a large list of document IDs
Alexander
Alexander
01:59 AMThank 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
Jason
02:02 AMYeah 1000 IDs should be fine
02:03
Jason
02:03 AMTypesense will take care of pagination as well
Typesense
Lightning-fast, open source search engine for everyone | Knowledge Base powered by Struct.AI
Indexed 2786 threads (79% resolved)
Similar Threads
Using Typesense to Search Specific Document IDs
Tshepo inquired about performing specific document ID searches in Typesense. Jason advised using the `filter_by=id:=[1,2,3,etc]` function or directly querying Typesense.
5
32mo
Solved
Troubleshooting exclude_fields in Typesense
Vadali reported an issue with exclude_fields, but later discovered a bug in their own query.
4
6mo
Solved
Effective Document Deletion Strategies in Typesense
Adrian asked about deleting potentially non-existent documents. Pantelis suggested using IDs for document deletion or queries within delete function. Adrian decided to use query-based deletions.
7
2mo
Solved