【发布时间】:2016-02-27 21:57:18
【问题描述】:
所以我使用 Algolia.com 为用户建立索引以便快速搜索。
索引中的示例对象:
{
id: 1,
username: "john.doe",
name: "John Doe",
attributes: {
gender: "male",
hair_color: "blonde",
eye_color: "blue",
height: 165
}
}
我想通过属性对象中的特定属性(对象键)过滤结果。
我认为也许使用 facetFilters 可以完成这项工作,但我无法让它发挥作用。
我已经尝试了这个代码的许多变体:
user_index.search('', {
facets: '*',
facetFilters: ['attributes.hair_color:blonde', 'attributes.eye_color:blue']
}, function(error, data) {
console.log(error, data);
});
-- / --
user_index.search('', {
facets: '*',
facetFilters: ['hair_color:blonde']
}, function(error, data) {
console.log(error, data);
});
【问题讨论】:
-
您是否已将
attributes.hair_color添加到您的attributesForFaceting(在您的索引仪表板中显示选项卡)?您应该可以轻松地通过user_index.search('', { facetFilters: 'attributes.hair_color:blonde' }, function () { console.log(arguments); })进行搜索。 -
@Jerska 谢谢!这解决了我的问题!这么简单的事情。
-
@LeviCole Algolia 的搜索 API没有什么简单的。它被疯狂地过度设计,使得执行最简单的搜索变得异常困难。
标签: javascript json search indexing algolia