Algolia初始搜索参数instantsearch.js [英] Algolia initial search parameters instantsearch.js

查看:221
本文介绍了Algolia初始搜索参数instantsearch.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个索引,我试图在algolia中传递查询的初始值。我正在使用instantsearch.js,现在它只是加载我的索引中的所有内容。如何在页面加载时将初始值传递给索引?

I have an index where I am trying to pass initial values for the query in algolia. I am using the instantsearch.js and right now it just loads everything from my index. How can I pass initial values to the index on page load?

例如从索引中选择*,其中Category ='Careers'(将职业作为加载值传递)

For example Select * from index where Category='Careers' (passing careers as a value on the load)

我搜索了这个文档并且无法弄明白。

I've searched the documentation for this and cant figure it out.

另外,我需要通过多个值,如下所示:

Also, I need to pass multiple values, so something like:

从索引中选择*,其中Category ='Careers'或'Skills'或'Interests'(带或陈述)

谢谢!

推荐答案

我假设您正在使用refinementList小部件: https://community.algolia.com/instantsearch .js文件/文件/#refinementlist 。在您的数据的类别属性上。

I assume you are using a refinementList widget: https://community.algolia.com/instantsearch.js/documentation/#refinementlist. On the 'category' attribute of your data.

如果是这样,您可以这样做:

If so, you can do this:

var preselectedCategories = ['Careers', 'Skills'];

var search = instantsearch(applicationID, apiKey, {
  ...other parameters,
  searchParameters: {
    disjunctiveFacetsRefinements: {
      category: preselectedCategories
    }
  }
})

您还需要做这在refinementList实例化中:

You will also need to do this in the refinementList instantiation:

var refinementList = instantsearch.widgets.refinementList({
  transformData: {
    item: function(item) {
      if (preselectedCategories.indexOf(item.name) !== -1) {
        item.cssClasses.label += ' pre-selected';
      }

      return item;
    }
  }
});

然后所有预选的类别项目将具有预先选择的css
类别默认。

Then all the preselected categories items will have the "pre-selected" css class by default.

然后你可以使用css和这个类名来做:

Then you can use css and this class name to do:

.pre-selected {
  display: none;
}

告诉我

这篇关于Algolia初始搜索参数instantsearch.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆