MongoDB 全文搜索,自动完成两个字段

MongoDB full text search, autocomplete on two fields

我正在尝试实施 MongoDB atlas search,并且 objective 在 2 个字段上自动完成。

我目前有这个实现:

const searchStep = {
    $search: {
        // Read more about compound here:
        // https://docs.atlas.mongodb.com/reference/atlas-search/compound/
        compound: {
            must: [
                {
                    autocomplete: {
                        query,
                        path: 'name',
                    },
                },
                {
                    autocomplete: {
                        query,
                        path: 'description',
                    },
                },
            ],
        },
    },
}

这似乎不起作用,似乎只有在 both 匹配名称 AND 描述时才起作用。我该如何解决这个问题,所以我查询 名称和描述?

我现在尝试使用 通配符 选项:

{
    wildcard: {
        query,
        path: ['name', 'description'],
        allowAnalyzedField: true,
    }
}

但通配符解决方案似乎不起作用 - 没有返回相关结果...

如果您尝试匹配 namesubscription,请使用 should: 而不是 must:

must 将要求所有子查询都匹配,而 should 要求其中只有 1 个匹配。

const searchStep = {
    $search: {
        // Read more about compound here:
        // https://docs.atlas.mongodb.com/reference/atlas-search/compound/
        compound: {
            should: [
                {
                    autocomplete: {
                        query,
                        path: 'name',
                    },
                },
                {
                    autocomplete: {
                        query,
                        path: 'description',
                    },
                },
            ],
        },
    },
}