如何按布尔属性过滤我的搜索?

How can i filter my search by an boolean atrribute?

如何过滤匹配项?我有这样的结构:点击有一个属性 'like' 它是一个布尔值,我只想显示带有 like===true

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

在 部分我可以使用过滤器吗?

这是我要搜索的配置,指的是这个文档https://www.algolia.com/doc/api-reference/widgets/configure/react/

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

我尝试使用 <Configure filters="category:secure" hitsPerPage={100} /> 它有效,但是当我尝试使用 bool 属性时它不起作用,这是怎么回事?

我试过但没有用,虽然这个效果很好我需要布尔型属性

使用字段 free_shippingConfigure 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 是布尔属性。

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

首先您应该从控制面板进行配置

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/

或来自其 api 客户:

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

更多信息: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.

那么这就可以了

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