Using "attributeForDistinct" in React

Hi there everyone!

I am just wondering what’s the best way to use distinct by Attribute using Algolia React.

I found the “attributeForDistinct” but apparently its not applicable using React?

I have tried under the Config with not luck (give me a 400).

<Configure
attributeForDistinct={[‘location’]}
distinct={true}
/>

Anyone could achieve a distinct search by attribute using the React library?

Cheers.
Andre.

Hi @abocati

There are 2 things to note about attributeForDistinct.

  • You can define only one attribute for distinct. (ie can’t work with an array)
  • It must be done at indexing time ; it cannot be defined or overridden at query time. (ie can’t work in React IS)

see https://www.algolia.com/doc/api-reference/api-parameters/attributeForDistinct/#usage-notes

I hope this helps.

Thank you for your reply @ Youcef

Any way of achieving the same result using the React library?

I need a distinct search for a single attribute (‘location’) !

I have some multiple locations (Cities) and need to search them without any duplicated results.

Thanks again.

Not with the react library. But I guess you use the connector and pass the array of results through the uniq function from lodash for example: https://lodash.com/docs/4.17.14#uniqBy

The best is still to do it on indexing time.

1 Like