Grouping objects in algolia using indices or pagination?

Hi everyone,

I have an application with a collection view. Whenever I click on a specific cell, it should fetch 50 objects from the server to display them. But of course, depending on which cell I clicked, the 50 objects being fetched, differ.

If I click on the first cell, the first 50 objects should be fetched. If I click on the second cell, the next 50 objects should be fetched.

How can I implement such use case?

Thanks in advance!

Hi @kaan548,

It may depend on which Algolia extension or API you are using, as well as the way you have your data indexed. in general, your click on the cell could trigger a specific search query and/or filter. You could then show the top 50 results returned from the search.

To answer more specifically, could you give more details about your implementation environment and how your data is indexed?

Hello @cindy.cullen,

thanks for the reply. As the api for the search, I am using InstantSearch actually. Regarding your question with indexing the data… Actually, my data is not indexed at all on the algolia server. There is no attribute indicating the index. Is there a way, I can still do that without adding a specific attribute?

Best regards,

Hi @kaan548,

I’m not completely sure I understand your question.

You should be accessing your index with your Instantsearch like this:

const searchClient = algoliasearch('APP_ID', 'Search_API_KEY');

const search = instantsearch({
  indexName: 'index_name',

Can you create a codesandbox demonstrating what you are trying to do with your Algolia index?

We have starter templates for codesandbox here.

Let us know when you have the codesandbox working and let us know exactly what you are trying to do to get your desired results.

1 Like

Hello @cindy.cullen :slight_smile:

It has been a while but I am still stuggling with this issue. Thanks for the code example above, but since I am using Swift for IOS, I couldn’t transfer it to my use case.

I try to explain what I am trying to do.
I have a method that should fetch all objects from the algolia server

    func loadParticipationContentByChallengeId() {
    dataAccessService.countNumberOfParticipants(completionHandler: { (participationArray) in
        self.participationArray = participationArray
    }, challengeId:

So the result is an array with several objects.

Let’s say, I get 200 results back. For every group of 50 records, I want to have something like a “cluster”. But a cluster is nothing than a collection view cell.

Whenever you click on the collection view cell, you are redirected to another view and then I want to fetch the corresponding 50 records.

I don’t have any attributes on my data for indexing though.

Can’t this not be solved by using PAGINATION? If I increase pagination to 50, then I click on the first collection view cell and load page 0. Once I click on the second collection view cell, I get the data from page 1 etc…

Best regards,

Hi @kaan548,

I’m not sure I understand if you aren’t using an Algolia index with attributes. Could you write to with your application ID so that we can investigate further?

Hi @cindy.cullen

I’m sorry, I guess I miscommunicated something. I have an index to fetch data from. I just meant, that within my index, I have attributes such as challengeTitle, challengeId, challengeDescription etc.
But I don’t have any numeric attribute to store some kind of an index value.

Hi @kaan548,

I think I understand what you are trying to achieve.
In your SingleIndexSearcher you can directly access the Query object via singleIndexSearcher.indexQueryState.query path. Query object gives you an access to page and hitsPerPage properties which you can set manually and get the required results.

Thanks Vladislav :slight_smile: So you also think, pagination would be the solution?