Search distinct items with facet count

Hi,
we are trying to display the facet count of each distinct item we are displaying, but we can’t figure it out :confused:

We are using vue-instantsearch.
The index looks like:

[ { "authorName": "John Doe", "authorId": 42, "bookId": 987 }
, { "authorName": "John Doe", "authorId": 42, "bookId": 4567 }
, { "authorName": "John Doe", "authorId": 42, "bookId": 34 }
, { "authorName": "Hemingway", "authorId": 98, "bookId": 6789 }
, { "authorName": "Hemingway", "authorId": 98, "bookId": 6789 }
, { "authorName": "Rollings", "authorId": 234, "bookId": 94706 }
]

Distinct attribute is set on authorId.
Attribute for faceting is set on authorId.

Almost like the guy there vvvvvvv, we want to have the facet count on each item retrieved

And retrieve something like:

[ { "authorName": "John Doe", "authorId": 42, "bookId": 987,     facets: 3 }
, { "authorName": "Hemingway", "authorId": 98, "bookId": 6789 ,  facets: 2 }
, { "authorName": "Rollings", "authorId": 234, "bookId": 94706,  facets: 1 }
]

We’ve been trying without success stuff like:

  <infinite-hits :facets="['*']" :response-fields="['facets']">

and even messing with maxFacetsHits (but we are stuck at a 100 results!) and mapping that on to the items retrieved.

Any other working solution is welcome!

Additional question: how would we be able to sort the items on this count?

Thanks for the help!

Hi @jean-guillaume ,
You cannot get the results as if you’re using SQL, but I may have a solution for you.

Since it’s already configured as a facet, you can get the counts per facet.

↑ In the example above, I use ais-index and inside it ais-refinement-list with a facet attribute. Then we will receive the search results including the facet counts.

And you can create a custom component using connectAutocomplete. Its name can be a bit confusing but you could think of it as connect multi indices. So in the custom component, it has access to all the indices and pinpoint the facet counts you want.

Let me know how it goes and if you have any question.

1 Like

Hello @eunjae.lee and thanks for the help!

This clean solution of yours does not completely solve the whole issue. Indeed, still only the 100 (max) first facets are retrieved.

Since sorting by the count result is a requirement, instead we went with pre-computing this value and save it in our records. It’s not dynamic as we first wanted it, but it solves 80% of our needs for now.

Hi, actually you can increase the number of facets up to 1000:

<ais-configure
  :hits-per-page.camel="1"
  :max-values-per-facet.camel="1000"
/>

If that’s enough for you, you don’t have to maintain the index. By the way I’m wondering why you need that many facets. Could you explain your use case?

Thanks

:confused:

We are listing for our clients their employees and apps they use.
Most of them have 100-400 employees and 200+ apps.
We can’t show only the related count for just a 100 of them when scrolling down the list

Hi there,

The hard limit is 1000, not 100. Let us know if 1000 isn’t going to solve your problem. We can think about alternatives.