I want to select some IDs (e.g. 200,201,202), tag ...
# community-help
b
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?
j
@bnfd Do you have a screenshot / mockup of what you mean?
b
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
j
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...
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
In any case, if the Algolia link solves your use case, you can do the exact thing in Typesense as well
b
that is correct, user-specific favorites. fav1 could be IDs (100,101,102) fav2 could be (100,150) for example
i'm checking the thread you linked
this is different from a facet right?
j
Faceting by a field just means that you're counting how many records in the result have a particular value for that field
b
thanks!
i think the other thread is about retrieving the users?
j
The other thread is about retrieving movies from user created list of movies
Similar to the example you brought up...
b
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"
is it the same approach?
j
Yes it is. So from that thread:
Copy code
{
  description: "...",
  userids_tagged_comedy: [1, 2, 3, 4],
  userids_tagged_thriller: [1, 2, 10, 42],
}
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
b
thanks a lot
j
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?
b
yes
j
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:
Copy code
// 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.
Since you're using two collections, you might have to build a custom instantsearch refinementList widget to have queries be sent to both collections...
b
ah forgot to mention, user1 only searches user1 collection, user2 only searches user2 collection etc.
j
Oh I see, in that you don't even need federated search.
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
b
so i create the schema with 'tags' included, then do a partial update to add the "comedy" tag?
and how do i create the "comedy" filter on instantsearch refinementList dynamically? sorry if it's a dumb question
j
so i create the schema with 'tags' included, then do a partial update to add the "comedy" tag?
Correct.
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?
b
yes
j
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"
b
oh thanks, i will try tomorrow
@Jason Bosco 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. 😕
j
Oh I just noticed that the query in the JS snippet is "Harry", but in curl it's "Harry Potter"... I'll fix that.
b
ok, so in curl and js I get found 27 . I guess the docs refer to another collection?
j
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
We’ve fixed various bugs over the versions to improve relevancy which will cause slight variations in number of docs found
👍 1
b
yeah i meant the two extra docs
for 9k records (books.jsonl) i thought the document ingestion is slow (around a minute), is there a workaround for this?
i mean, is it meant to take that long or is it an issue on my end?
j
@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
b
@Jason Bosco great, thanks. have you found that the optimal BATCH_SIZE is 1000?
j
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