How to use facet filtering toward nested data with large varieties

I’m using Algolia to enable text search in the data of Firebase Realtime Database by syncing with Cloud Functions.

The structure of Firebase DB is as below. At this point, I’m just copying the same schema into Algolia.

"requests" : {
    "uid_of_request": {
         "text": "abcdefg...",
         "companyIds": {
                "companyId1": true,
                "companyId5": true,
                "compnayId8": true
          }
      },
...

model in TypeScript.

class Request {
  $key: string;
  text: string;
  companyIds: {[key: string]: boolean};
}

Algolia config
Searchable Attributes: text
Attribute for faceting: companyIds

What I want to do is to filter request data with such like “companyIds.companyId5:true”. The use case is that a person working at a company can filter requests which his/her company got involved in or not. I’ve already tried this and this has worked.

However, we’ll have thousands of companies. When a company replies a request, the request have the companyId in “companyIds”.

My question is I’m on the right track or not? If not, I don’t care about changing schema of Firebase or Algolia.

One of my worries is we’d have many facets according to the number of companyIds. Also dashboard would be very busy with facets and pull-down for setting attribute would not work with thousands of choices.
Plus, in terms of search performance, I’m not sure this is a feasible way or not.

P.S. I had thought to have just array like “companyIds: [“companyId1”, “companyId5”, …]” but this is not good way for Firebase.

Would be appreciated if you give me any help.

Thanks

I think the following way would be a better way?

Converting index signature of companyIds in Firebase to array in Algolia by Cloud Functions. But dashboard would be still busy if I have thousands of companyIds…

Algolia schema

"requests": {
  "uid_of_request": {
       "text": "abcdefg..",
       "companyIds": ["companyId1", ......]
Algolia config:
Searchable Attributes: text
Attribute for faceting: companyIds

I’m not sure performance of searching with facet would be feasible or not at this point, though…

Hello !

Thanks for reaching out to us !
Yes, converting your companyIds to an array is a much better solution - from an algolia/faceting perspective.
From a performance standpoint, it should be ok. Only drawback would be the count per facets that might not be accurate (it is an estimation)

Does that answer your question ?
Let me know how it goes !

2 Likes

Thank you for your response! I’ve tried the conversion and that worked well as expected.
It doesn’t matter the accuracy of count in dashboard to me so that this would be my solution.

But when I have hundreds of companyIds, dashboard can still work? I guess it would list entire varieties of facets. If I set up companyId array as a facet, it’d turn out to be hundreds as well or the dashboard omits listing of the variety of facet values at a certain point? or can I turn it off?

The dashboard will only show top values for each facet sorted by count, so you’ll be ok there.

If you have a lot of facet values that you can’t display at once, you can now provide a search box for them. Check out the search for facet values feature.

1 Like

Thanks a lot for your help! I’ll try it later.

1 Like