iOS: Get Additional Facet Details

I am trying to build an iOS app to query and list some objects to browse instead/in-addition to directly searching or refining over an index that i have in algolia.

when i execute the query with the general parameters and no facet filtering , all works fine and i get all my objects in the hits node, and i get a facets node too, with the name of the facet and a number signifying the number of hits that carry this facet.

TLDR: Can I modify the facets node of the query response to have additional data, ex: Image URLs?

I can easily show the refining options user has, like facet and the number of hits under that facet, But what if I want to show additional data , such as an image against each facet ?

Basically if i have a single tableView or collectionView now, showing all the hits , I want to modify that so I can present the user with categorised data.

like multiple tableViews or multiple collection View or even complex UI such as A tableView where each row has a collectionView, depending on the facets and each cell has an image.

is that possible?

Hi @kinshuk.kashyap,

Thank you for contacting us! that’s a good question. So if you check the possible fields in a response, you’ll see that there is no direct way to add a field for each facet.

I can think of 2 ways to solve this problem:

  • Include a FacetImageURL attribute inside each of your entry. In that way you’ll have this information when you fetch your results
  • Create a new index FacetIndex that contains information around each facet (ID, Name, ImageURL etc). When you need the ImageURL, you would query this index. But this will require more work as you will need to do 1 more operation and will need to aggregate the 2 indexes on the frontend.

Hey @guy.daher , Thanks so much for an elaborative response.

I guess I’ll go with the second solution, because if i use the first solution the 20 hits that i’m gonna receive might miss out some facet, in turn hiding a whole facet from my user’s browsing category.

Although the second solution does present me with the complexity of maintaining both the indexes in sync.
So for example, every time I am adding a new movie to my movies index , I have got to update the genre index as well, if this is the first of that genre movie, then i’ll have to add that genre data such as genreImageURL, genreRating, genrePopularity etc.

Also I’ll have to think of scenarios for multiple facets on one item and dynamic automated facet updation.

Anyways, Guess I am thinking out loud :smile: , Thanks so much.

I agree with you that the 2nd solution is more appropriate for the reason you stated :slight_smile:

Yes indeed, you will have to update 2 indexes when you have new genres, I agree, but that happens in any application.

You’re right for the multiple facets on one time, you’ll have to decide what you want to do there, but you’ll have all the necessary data on your frontend, so you can do whatever with it :smiley:

Glad to help!