#community-help

User-Specific Tagging and Filtering in UI

TLDR 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.

Powered by Struct AI

1

Aug 24, 2021 (29 months ago)
bnfd
Photo of md5-ca6495d5be926db80e09aabf066f4b8b
bnfd
12:04 AM
I want to select some IDs (e.g. 200,201,202), tag them as "selection1" and make it available on the UI. What is the recommended way to do this?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
12:22 AM
bnfd Do you have a screenshot / mockup of what you mean?
bnfd
Photo of md5-ca6495d5be926db80e09aabf066f4b8b
bnfd
12:26 AM
hey Jason, let's say on the recipe demo site, I choose two apple recipes and save that selection as "my favorite apple recipes" which should appear as a category on the left side
12:28
bnfd
12:28 AM
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
12:29 AM
Ah I see. This is a slight variation of what's discussed here: https://typesense-community.slack.com/archives/C01P749MET0/p1625683625475800?thread_ts=1625683440.475500&cid=C01P749MET0

Let me know if that helps...
12:31
Jason
12:31 AM
re: the Algolia link, it sounds like it only talks about non user-specific tags. Meaning that there's one global "favorite apple recipes", but from your description, I understood it as you want a user-specific favorites list
12:31
Jason
12:31 AM
In any case, if the Algolia link solves your use case, you can do the exact thing in Typesense as well
bnfd
Photo of md5-ca6495d5be926db80e09aabf066f4b8b
bnfd
12:33 AM
that is correct, user-specific favorites. fav1 could be IDs (100,101,102) fav2 could be (100,150) for example
12:33
bnfd
12:33 AM
i'm checking the thread you linked
12:34
bnfd
12:34 AM
this is different from a facet right?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
12:36 AM
Faceting by a field just means that you're counting how many records in the result have a particular value for that field
bnfd
Photo of md5-ca6495d5be926db80e09aabf066f4b8b
bnfd
12:40 AM
thanks!
12:42
bnfd
12:42 AM
i think the other thread is about retrieving the users?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
12:45 AM
The other thread is about retrieving movies from user created list of movies
12:46
Jason
12:46 AM
Similar to the example you brought up...
bnfd
Photo of md5-ca6495d5be926db80e09aabf066f4b8b
bnfd
12:46 AM
just to make sure using the movie example: in a collection of movies i want to select ids 100,101,102 and save it as "comedy" and ids 100,150 as "thriller"
12:46
bnfd
12:46 AM
is it the same approach?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
12:47 AM
Yes it is. So from that thread:

{
  description: "...",
  userids_tagged_comedy: [1, 2, 3, 4],
  userids_tagged_thriller: [1, 2, 10, 42],
}
12:48
Jason
12:48 AM
When a user with user ID 1, creates a list with movies IDs 100,101,102 called "comedy", you'd add their user_id to each of these movies, under an array field called userids_tagged_comedy
bnfd
Photo of md5-ca6495d5be926db80e09aabf066f4b8b
bnfd
12:51 AM
thanks a lot
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
12:51 AM
Actually, in your case, you also want to show it as a "personalized" filter for each user, so they can filter through just their tags right?
bnfd
Photo of md5-ca6495d5be926db80e09aabf066f4b8b
bnfd
12:51 AM
yes
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
12:59 AM
Another option in your case would be to store all movies in one collection... Then for each user create a separate collection of movies that they've added to a list. For eg:

// Collection name: movies_user_1
[
  {
    id: "movie_100",
    description: "...",
    tags: ['comedy', 'thriller']
  }

and so on.

So when a user adds something to a list, you'd only add to their specific collection.

Then when searching, you'd use multi search / federated search to search / filter both the main movies collection and the user's own movies collection.
01:00
Jason
01:00 AM
Since you're using two collections, you might have to build a custom instantsearch refinementList widget to have queries be sent to both collections...
bnfd
Photo of md5-ca6495d5be926db80e09aabf066f4b8b
bnfd
01:01 AM
ah forgot to mention, user1 only searches user1 collection, user2 only searches user2 collection etc.
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
01:01 AM
Oh I see, in that you don't even need federated search.
01:02
Jason
01:02 AM
Let users create their own list from the global movie collection, add their selections to a user-specific movies collection, and then later only query/filter their own collection
bnfd
Photo of md5-ca6495d5be926db80e09aabf066f4b8b
bnfd
01:05 AM
so i create the schema with 'tags' included, then do a partial update to add the "comedy" tag?
01:06
bnfd
01:06 AM
and how do i create the "comedy" filter on instantsearch refinementList dynamically? sorry if it's a dumb question
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
01:09 AM
> so i create the schema with 'tags' included, then do a partial update to add the "comedy" tag?
Correct.
01:09
Jason
01:09 AM
> and how do i create the "comedy" filter on instantsearch refinementList dynamically?
It's one filter / refinementList with all of the user's tags right?
bnfd
Photo of md5-ca6495d5be926db80e09aabf066f4b8b
bnfd
01:09 AM
yes
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
01:10 AM
Then the standard refinementList implementation will work out of the box.

So something like this: https://github.com/typesense/showcase-ecommerce-store/blob/5cf0597807da2429af00a73c1c2e69fe6bd3fafb/src/app.js#L116-L124

but set the attribute to "tags"
bnfd
Photo of md5-ca6495d5be926db80e09aabf066f4b8b
bnfd
01:13 AM
oh thanks, i will try tomorrow
02:44
bnfd
02:44 PM
Jason I'm following the steps in the documentation with books.jsonl, https://typesense.org/docs/0.21.0/guide/building-a-search-application.html#searching-for-books . The response in the docs state found=62, with curl I get "found": 27, with JS I get found: 64. 😕
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
03:17 PM
Oh I just noticed that the query in the JS snippet is "Harry", but in curl it's "Harry Potter"... I'll fix that.
bnfd
Photo of md5-ca6495d5be926db80e09aabf066f4b8b
bnfd
03:26 PM
ok, so in curl and js I get found 27 . I guess the docs refer to another collection?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
03:29 PM
It’s the same collection, but JS snippet is using a different query and curl snippet is using a different query, but the output shown us from the JS snippet. Also the output shown in the docs is from an older version of Typesense, so it might return one or two extra documents in the results
03:29
Jason
03:29 PM
We’ve fixed various bugs over the versions to improve relevancy which will cause slight variations in number of docs found

1

bnfd
Photo of md5-ca6495d5be926db80e09aabf066f4b8b
bnfd
03:29 PM
yeah i meant the two extra docs
03:32
bnfd
03:32 PM
for 9k records (books.jsonl) i thought the document ingestion is slow (around a minute), is there a workaround for this?
03:41
bnfd
03:41 PM
i mean, is it meant to take that long or is it an issue on my end?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
05:40 PM
bnfd the guide uses the single document creation endpoint, so indexes documents one by one, which is slow. In a production application you want to use the documents/import bulk indexing endpoint, to index a large number of documents. With this endpoint, I've been able to import 2M documents in ~3mins
bnfd
Photo of md5-ca6495d5be926db80e09aabf066f4b8b
bnfd
05:44 PM
Jason great, thanks. have you found that the optimal BATCH_SIZE is 1000?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
05:59 PM
If you use the import endpoint, even the default BATCH_SIZE should be sufficient. What that batch size means is that after every X records, it will pause briefly check for any other search requests in the queue, service those and then resume the import. So for high traffic use cases you actually want a low batch size

Typesense

Lightning-fast, open source search engine for everyone | Knowledge Base powered by Struct.AI

Indexed 3015 threads (79% resolved)

Join Our Community

Similar Threads

Troubleshooting Typesense Setup and Understanding Facets and Keywords

Demitri encountered errors when exploring Typesense for the first time. Jason guided them through troubleshooting and discussed facets, keyword settings, and widget configurations. Helin shared a Python demo app and its source code to help Demitri with their project.

1

56
21mo

Discussions on Typesense, Collections, and Dynamic Fields

Tugay shares plans to use Typesense for their SaaS platform and asks about collection sizes and sharding. Jason clarifies Typesense's capabilities and shares a beta feature. They discuss using unique collections per customer and new improvements. Kishore Nallan and Gabe comment on threading and data protection respectively.

3

45
35mo

Fixing Multiple Document Retrieval in Typesense

Phil needed an efficient way to retrieve multiple documents by id. Kishore Nallan proposed a solution available in a pre-release build. After some bug fixing regarding id matching by Jason and Kishore Nallan, Phil successfully tested the solution.

4

26
26mo

Querying and Indexing Multiple Elements Issues

Krish queried fields with multiple elements, which Kishore Nallan suggested checking `drop_tokens_threshold`. Krish wished to force OR mode for token, but Kishore Nallan admitted the feature was missing. Krish was able to resolve the issue with url encoding.

34
12mo

Understanding and Implementing Typesense Dart Library with Flutter

Alexandro sought help with the Typesense Dart library. Jason explained that the library is in progress, discussed utilizing other HTTP libraries, and provided detailed instructions on utilizing Typesense with Flutter. Alexandro provided feedback on the Typesense UI and expressed interest in creating a tutorial video.

10

82
32mo