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

查看:18
本文介绍了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?

例如 Select * from index where 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:

select * from index where Category = 'Careers' or 'Skills' or 'Interests' (with or statements)

select * from index where Category = 'Careers' or 'Skills' or 'Interests' (with or statements)

谢谢!

推荐答案

我假设您使用的是一个提炼列表小部件:https://community.algolia.com/instantsearch.js/documentation/#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天全站免登陆