javascript - Algolia 按嵌套属性 JavaScript 过滤

标签 javascript json search indexing algolia

所以我使用 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);
});

请在此处找到文档:https://www.algolia.com/doc/javascript

最佳答案

只是为了能够将此问题标记为已回答:

您应该将 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/

相关文章:

ios - 不使用 SearchBar 过滤 UITableView

javascript - 在 p5.js 中使用 For 循环创建形状

json - 我可以在发布之前获取 http.NewRequest 的大小吗?

javascript - 空字符串检查评估错误

javascript - Facebook Messenger Bot Webhook 问题

perl - 如何使用 LWP 发出 JSON POST 请求?

python - 寻找最接近值算法

php - 搜索功能在我的 PHP MySQL 查询中不起作用

javascript - 如何使用 jquery 设置变量(更改)属性名称?

javascript - 获取 UTC 时间戳