我正在尝试将自动完成结果从 Algolia 过滤回我的应用程序。我添加了过滤器来检查我存储在 algolia 中的数据中是否包含 draft=0
。
autocomplete('#search-box', {hint: false}, [
{
source: autocomplete.sources.hits(index, {hitsPerPage: 5}),
displayKey: 'title',
filters: 'draft=0',
templates: {
suggestion: function(suggestion) {
return suggestion._highlightResult.title.value;
}
}
}
到目前为止,它不会过滤,仍然返回草稿内容。我不想在搜索中显示的文章是我的 algolia 索引中的 draft: 1
。
最佳答案
filters
是数据源的参数,而不是autocomplete
本身。
尝试:
autocomplete('#search-box', {hint: false}, [
{
source: autocomplete.sources.hits(index, {hitsPerPage: 5, filters: 'draft=0'}),
displayKey: 'title',
templates: {
suggestion: function(suggestion) {
return suggestion._highlightResult.title.value;
}
}
}
关于javascript - Algolia 自动完成筛选结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38791757/