所以我使用 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);
});
搜索。
关于javascript - Algolia 按嵌套属性 JavaScript 过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33910947/