#community-help

Implementing Item Search Feature on User Favourites

TLDR Lukas sought to implement a search feature on users' favourite items. After initial clarification from Kishore Nallan, Jason suggested structuring data differently by attaching user favourites to the actual items, which Lukas understood.

Powered by Struct AI
+11
1001
7
23mo
Solved
Join the chat
Oct 15, 2021 (23 months ago)
Lukas
Photo of md5-d9deaf8d1683beb47108307453fe58bc
Lukas
08:47 AM
Hello,

I want to implement search feature on users favorite items.

Each user has a field in their document - favoriteItems which is array of strings that are references to the documents.

Is there a way to pass that array to react instant search, so it could create a filter based on the document Id, so that it would only search for documents that are within that array.

And if there is such functionality, is there a limit to or I can add array with 100+ items in it.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
09:16 AM
👋 Jason Will be able to go into the detail on this question later today.
+11
1001
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
06:03 PM
Lukas It sounds like your end goal is to allow users to search for keywords in their favorited items. If so, you want to structure the data a bit differently, instead of a list of favorite document ids within each user record.

Here's a thread that outlines this: https://typesense-community.slack.com/archives/C01P749MET0/p1625683625475800?thread_ts=1625683440.475500&cid=C01P749MET0
Lukas
Photo of md5-d9deaf8d1683beb47108307453fe58bc
Lukas
10:29 PM
Jason not the keywords, but I want to search the actual items that user has favorited. 

You can see similar feature on instagram when you want to search through people that particular account follows.
10:30
Lukas
10:30 PM
So, instead of having userFavorites(with restaurant ids) field in user document, I would have to attach a field to the actual restaurant with all of the users that have favorited that restaurant? 
Let me know if I am understanding this properly.
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
10:30 PM
That's right
10:30
Jason
10:30 PM
Also, by keywords, I meant "man" in your example above