如何在 运行 MongoDB Atlas 全文搜索之前应用过滤器?

How to apply a filter, before running MongoDB Atlas full text search?

根据关于 Atlas Search 的文档,它指出:

$search must be the first stage of any pipeline it appears in.

好吧,如果是这样,您如何应用 Mongo 过滤器。 在搜索的输出上应用这些过滤器似乎非常违反直觉?

我们正在考虑使用 Mongodb 全文搜索作为 Algolia 的替代方案,但这种限制似乎很奇怪

当前流水线:

const pipeline = [
    {
        $search: {
            text: {
                query,
                path: fields,
                fuzzy: {
                    maxEdits: 1,
                    maxExpansions: 50,
                },
            },
        },
    },
    {
        $match: {
            someField: 1,
        },
    },
];

在这种情况下,最好在 Atlas Search as a number, as it supports numeric types using the range operator and compound 中索引 someField 以合并结果。由于整个查询在 Lucene 中是 运行,它应该 return 更快地得到结果。

const pipeline = [
    {
        $search: {
            compound: {
                should: {
                    text: {
                        query,
                        path: fields,
                        fuzzy: {
                            maxEdits: 1,
                            maxExpansions: 50,
                        },
                    },
                },
                filter: {
                    range: { 
                        path: "someField",
                        lte: 1,
                        gte: 1
                    }
                }
            }

        }
    }
];