Algolia 按嵌套属性 JavaScript 过滤 [英] Algolia filter by nested attribute JavaScript

查看:41
本文介绍了Algolia 按嵌套属性 JavaScript 过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我使用 Algolia.com 来索引用户以便快速搜索.

So I am using Algolia.com to index users for quick searching.

索引中的一个示例对象:

An example object in index:

{
    id: 1,
    username: "john.doe",
    name: "John Doe",
    attributes: {
        gender: "male",
        hair_color: "blonde",
        eye_color: "blue",
        height: 165
    }
}

我想通过属性对象中的特定属性(对象键)过滤结果.

I'd like to filter results by a specific attribute (object key) in the attributes object.

我想也许使用 facetFilters 可以完成这项工作,但我无法让它工作.

I thought maybe using facetFilters would do the job, but I am unable to get it working.

我尝试了此代码的许多变体:

I have tried many variances of this code:

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

推荐答案

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

Just in order to be able to mark this question as answered :

您应该将 attributes.hair_color 添加到您的 attributesForFaceting(索引仪表板中的显示选项卡)你应该很容易做到

You should add attributes.hair_color to your attributesForFaceting (Display tab in your index dashboard) You should be able to easily just do

user_index.search('', {
  facetFilters: 'attributes.hair_color:blonde'
}, function () {
  console.log(arguments);
});

搜索.

这篇关于Algolia 按嵌套属性 JavaScript 过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆