React-instantsearch: Retrieve objects based on certain condition.

Created on 29 Jan 2020  ยท  6Comments  ยท  Source: algolia/react-instantsearch

my object shape is:
{
...otherFields,
isApproved: false
}

so I want to fetch all the objects where isApproved is true

โ” Question

All 6 comments

Hi @developerk786, you can add arbitrary filters using the configure widget:

<Configure filters="isApproved:true" />

Or the toggleRefinement widget

<ToggleRefinement attribute="isApproved" value={true} />

Ok so it works with instasearch but what about fetching data with algolia client, algolia.getObject()

With getObject you give an objectID, so filtering doesn't make sense anymore at that point, but you can use search() to get one (or more) items based on a condition:

client.search('', {
  filters: 'isApproved:true',
  hitsPerPage: 1
})

This is of course limited, but if you want to find _all_ items based on a filter, you can use browse: https://www.algolia.com/doc/api-reference/api-methods/browse/

ok that nice but is there any option in algolia dashboard where I can set that thing, pardon my English.

You can not set a filter by default, but what you can do is prefilling an API key with the filter in it, so it can not be removed: https://www.algolia.com/doc/api-reference/api-methods/generate-secured-api-key/

ok thanks for your help

Was this page helpful?
0 / 5 - 0 ratings

Related issues

flouc001 picture flouc001  ยท  5Comments

hatched-danny picture hatched-danny  ยท  3Comments

vinhlh picture vinhlh  ยท  5Comments

flouc001 picture flouc001  ยท  4Comments

denkristoffer picture denkristoffer  ยท  4Comments