How can i filter my search by an boolean atrribute?

893 Views Asked by At

How can i filter the hits? i have this structure: the Hit have an attribute 'like' its a boolean, i want to show only the Hits with like===true

 <Configure hitsPerPage={100} />
   <Grid >
     <Grid >
       <Hits hitComponent={Hit} />
     </Grid>
   </Grid>

in witch part can i use filter?

This is my configuration to search, by mean this documentation https://www.algolia.com/doc/api-reference/widgets/configure/react/

<InstantSearch
        searchClient={vclient}
        indexName={`myVarClient`}
      >

i was trying with <Configure filters="category:secure" hitsPerPage={100} /> its worked but when i try with the bool attribute this dont work what is the wrong?

i tried with but dont worked, while with this worked good i need with the boolean like attribute

2

There are 2 best solutions below

0
On BEST ANSWER

Firstly you should configurate from the dashboard

Go to your dashboard and select your index. Click the Configuration tab. Under the Filtering and Faceting category, click on Facets. In the Attributes for faceting section, click on Add an Attribute and select the attribute you wish to declare for faceting. For each attribute, click the dropdown on the right and set them as “searchable”, “filter only” or “not searchable”. Don’t forget to save your changes this info is from: https://www.algolia.com/doc/guides/managing-results/refine-results/faceting/how-to/declaring-attributes-for-faceting/

or from its api client:

index.setSettings({
  attributesForFaceting: [
    'like',
  ]
}).then(() => {
  // done
});

more info: https://www.algolia.com/doc/api-reference/api-parameters/attributesForFaceting/#examples

Modifiers:# filterOnly: Defines an attribute as filterable only and not facetable.

If you only need the filtering feature, you can take advantage of filterOnly which will reduce the index size and improve the speed of the search.

You cannot define an attribute as both ‘filterOnly’ and ‘searchable’. The following therefore is not doable: filterOnly(searchable(attributeName)).

searchable: Defines an attribute as searchable.

then this will work

<Configure  filters="like:true" hitsPerPage={100} />
0
On

The Configure widget is the way to go for this use case. You have to ensure that the attribute provided is in the list of attributesForFaceting otherwise the filter won't work. Here is an example that uses the field free_shipping which is a boolean attribute.

<InstantSearch searchClient={searchClient} indexName="instant_search">
  <Configure filters="free_shipping:true" />
</InstantSearch>