简体   繁体   English

Instantsearch.js:使用来自Algolia的查询参数过滤初始搜索

[英]instantsearch.js: filter initial search with query parameter from Algolia

I've been trying to filter the initial search with this query parameter from Algolia with no success. 我一直在尝试使用来自Algolia的此查询参数过滤初始搜索,但没有成功。 What I've read in the docs is you have to add the query parameter and a query string but so far it do the job. 我在文档中读到的是,您必须添加查询参数和查询字符串,但到目前为止,它已经完成了工作。

This is the code I've been working with 这是我一直在使用的代码

var search = instantsearch({
  appId: 'API ID',
  apiKey: 'APY KEY SEARCH',
  indexName: 'per_posts_product',
   searchParameters: {
        facets: ['taxonomies.product_cat'],
        facetsRefinements: {'taxonomies.product_cat': 'Dual Daggers'}
    },
  routing: true
});

The values provided to the facetsRefinements should be an array not a string. 提供给facetsRefinements的值应为数组而不是字符串。 Here is an example that shows how to use it: 这是一个显示如何使用它的示例:

const search = instantsearch({
  appId: 'APP_ID',
  apiKey: 'API_KEY',
  indexName: 'INDEX_NAME',
  searchParameters: {
    facets: ['taxonomies.product_cat'],
    facetsRefinements: {
      'taxonomies.product_cat': ['Dual Daggers'],
    },
  },
});

Don't forget to declare your attribute as attributesForFaceting inside your index. 不要忘记在索引内部将attributesForFaceting声明为attributesForFaceting

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM