我有一个包含以下 JSON 键的索引,并且可以有两个值:
ApprovalFL: true
或者 ApprovalFL: null
我希望我的搜索结果只显示那些ApprovalFL: true
意味着它们已被批准在网站上显示的结果。
我尝试研究 Algolia Facet 方法(https://www.algolia.com/doc/guides/searching/faceting/#search-for-facet-values),但老实说我不太确定把它放在哪里我的代码,(开发人员最初设置了 Algolia……我还在学习)这是我的相关 javascript:https ://jsfiddle.net/vpnvt9vv/1
这是我的代码片段,其余的可以在上面的链接中找到:
var searchSong = instantsearch
({
appId: "---",
apiKey: "---",
indexName: "Song",
searchFunction: function (helper) {
var query = searchArtist.helper.state.query;
helper.state.index = "Song";
helper.state.hitsPerPage = 30;
helper.setQuery(query);
helper.search();
},
searchParameters:
{
hitsPerPage: 30
}
});
我已经在 Algolia 仪表板页面中添加了“attributesforFaceting”的密钥。
如果您想查看现场示例,请访问https://unearthapp.io并在搜索栏中输入字母“a”,您将看到来自名为“Turbo”的艺术家的两个结果,当 ApprovalFL 为 null 时我只希望显示 ApprovalFL 为 true 的歌曲
如果您需要更多信息,请告诉我,谢谢!
您可以使用facetFilters
并将其设置为["ApprovalFL:true"]
从您的代码结构中,您可以将其添加到searchFunction
OR中,searchParameters
如下所示。理想情况下,您希望在代码中添加一次搜索过滤器,否则由于在许多地方进行了声明,代码可能变得不可预测。
var searchSong = instantsearch ({
appId: "---",
apiKey: "---",
indexName: "Song",
searchFunction: function (helper) {
.
.
.
helper.state.facetFilters = ["ApprovalFL:true"];
.
.
.
},
searchParameters: {
hitsPerPage: 30,
facetFilters: ["ApprovalFL:true"]
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句