Searching within specific subset of data

Hello!

I am trying to accomplish the following:

Each document in algolia represents a post.
A user can like a post. This saves the post ID to an array stored in database (Firestore).
I would like it so that the user can search all liked posts.

I would like to know if the following approaches work, and if there is any guide/documentation to accomplishing it:

  1. Filtering on hundreds of ObjectIDs This is the brute force method of creating a huge filter that says uuid:1 OR uuid:5 OR uuid:400. Is this a feasible method, or will it quickly run into limits of Algolia?
  2. Filtering on the client side I have the data readily available on the client side. Am I able to implement my own filtering for the search client?

Approaches that I know don’t work:

  1. I have seen some pages that suggest maintaining a list on the documents in algolia. However, if I stored the userIds of everyone who liked a post, then it would quickly go over the max document size of 10k.

Any guidance would be greatly appreciated.

Hello,

This is an interesting use-case!

Algolia is really good when it comes to searching text. Could you tell me why you just want to use the post IDs and not associate them with some text that the end user could then search?

Depending on how big your user base is, you could then have an index containing one record per post with arrays of user IDs who liked them. You would then be able to filter the objects by user IDs who liked them and filter for a given userID.

If you need to maintain a large post-to-user matrix where you need to join data, this will be difficult to achieve this with Algolia and it would be probably better to turn to other types of databases such as SQL.

I hope that this answers most of your concerns.

Benjamin

Hi Benjamin,

My use case is that I have an application where users can bookmark articles, and it would be nice to have them be able to treat their bookmarked articles as their own “library” and be able to search within it.

However, it does not seem like this is something that is sustainable… Perhaps I will have to do something like make a separate document for each user+bookmark pair?

Anyways, thanks for your answer.

Dennis

As a quick follow-up, some of us also discussed this use-case internally and it would seems like a traditional relational database would be better suited for that. However, you can indeed build it with three Algolia indices: Users, Posts, Likes where:

  • Users contains the list of users
  • Posts contains the list of posts
  • Likes contains the association of users liking posts, where each record is a single like ({user_id, post_id})

I’d highly recommend you to take a look at our documentation guide Handling Data Relationships and specifically the section regarding our distinct feature which lets you group results having the same ID.