如果我有一个包含嵌套数组的文档,如何使用elasticlunr搜索嵌套数组?在凤凰城搜索时,我得到一个空数组。

以下是我的代码示例。谢谢,

const doc1 = 
    {
        "id": 123,
        "firstName": "jon",
        "lastName": "doe",
        "addresses": [
            {
                "line1": "123 any str",
                "city": "Some City",
                "state": "CA"
            }
        ]
    };
const doc2  {
        "id": 456,
        "firstName": "alan",
        "lastName": "park",
        "addresses": [
            {
                "line1": "1 some str",
                "city": "Phoenix",
                "state": "AZ"
            }
        ]
    }
this.index.addDoc(doc1);
this.index.addDoc(doc2);

let index = elasticlunr(function () {
            this.addField('firstName');
            this.addField('lastName');
            this.addField('addresses');
            this.addField('city');
            this.addField('state');
            this.setRef('id');
        });
        this.index = index;

searchFreeText() {
        return this.index.search("Phoenix", {
            fields: {
                firstName: { boost: 1, bool: "OR", expand: true },
                lastName: { boost: 1, bool: "OR" },
                addresses: { boost: 1, bool: "OR" },
                line1: { boost: 1, bool: "OR" },
                city: { boost: 1, bool: "OR" },
                state: { boost: 1, bool: "OR" },
            }
        });
    }

以上是我的代码示例。


如果我没记错的话,elasticlunr 与 Elasticsearch 无关,所以我删除了标签

@val 你是对的,elasticlunr 与 Elasticsearch 无关。我无法为 elasticlunr 创建新标签,因为我在 stackoverflow 中没有足够的徽章或积分。感谢您添加一个。

微信小程序

微信扫一扫体验

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部