通过嵌套属性JavaScript进行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);
});

搜索.

上一篇:在MySQL中索引VARCHAR


下一篇:Java商业友好的R树实现?