Ranking Favorite Food Records in Database Search Results
TLDR Julian asked for best practices to rank favorite food records in search results. John suggested using _eval
. Jason recommended adding a favorited_by_user_ids
array field to each record.
Jun 20, 2023 (3 months ago)
Julian
01:59 PMExample: User searches for "cream". The desired outcome would be:
1. "Heavy Cream (14% fat)" (<--- marked as favorite)
2. "Cream"
3. "Best cream"
Token position is relevant (2 matches before 3) and records marked as favorite should be on top if at least matched partially (prefix or infix).
Any ideas for best practices to achieve this? 🙏
John
03:20 PM_eval
. I created a collection with[
{"title": "Heavy Cream", "product_id": "1"},
{"title": "Cream", "product_id": "2"},
{"title": "Best Cream", "product_id": "3"},
{"title": "Wow I love this cream", "product_id": "4"},
]
which normally would give
Cream
Wow I love this cream
Best Cream
Heavy Cream
for "cream", but if you set
"sort_by": "_eval(product_id:[1,4]):desc,_text_match:desc"
you get
Wow I love this cream <- favorite
Heavy Cream <- favorite
Cream
Best Cream
There could be some performance costs if the user has a lot of favorites, but in my experience with large filters it hasn't been a problem even with many hundreds of items.
Note that this can result in worse matches marked as favorite coming before better matches, but I don't think it'll be much of a problem in practice (most of the time the entire candidate set will be quite good)
Julian
03:58 PMJason
04:11 PMJason
04:13 PMfavorited_by_user_ids
to each record, and store which users have favorited each product.Then you could do something like this:
"sort_by": "_eval(favorited_by_user_ids:=<CURRENT_USERS_ID>):desc,_text_match:desc"
Jason
04:14 PMTypesense
Indexed 2764 threads (79% resolved)
Similar Threads
Database Management and Personalized Search Queries Discussion
Alexander posed several database and search-related questions. Mac suggested considering GraphQL, considering performance and high availability needs, and leveraging Cloudflare workers. Kishore Nallan provided insights on the capabilities of Typesense and discussed the idea of search personalization using machine learning.
Implementation and Optimization of 'Similar Products' Feature
Stefan is considering using "curation" for pre-calculating similar products. Kishore Nallan suggests using preset API, but Stefan raised an issue with sorting based on non-stored values. The issue remains open for resolution.


User-Specific Tagging and Filtering in UI
bnfd asked for the best way to create user-specific tags available on the UI. Jason suggested using personalized filters and creating a separate collection for each user's movies. The duo clarified the use of 'tags' in schemas and the refinementList widget in instantsearch. They also discussed various approaches to import and search large document collections.
