gpt4 book ai didi

MongoDB 文本搜索和具有词干提取的多个搜索词

转载 作者:可可西里 更新时间:2023-11-01 10:40:20 25 4
gpt4 key购买 nike

我正在尝试在文本中包含多个单词(AND 运算)不会丢失词干。

例如:

db.supplies.runCommand("text", {search:"printers inks"})应使用 (printer and ink) 或 (printers ink) 或 (printers ink) 或 (printers inks) 返回结果,而不是使用打印机或墨水的所有结果。

这篇文章涵盖了作为 AND 操作搜索多个词,但解决方案不搜索词干词 -> MongoDB Text Search AND multiple search words .

我能想到的唯一方法是创建所有单词的排列,然后搜索排列的数量(可能很大)

这可能不是搜索大型集合的有效方法。

是否有更好、更智能的方法来做到这一点?

最佳答案

那么您是否有理由必须使用文本搜索?如果是我,我会使用正则表达式。

https://docs.mongodb.com/manual/reference/operator/query/regex/

像这样的事情在我的脑海中浮现。

db.collection.find({products:/printers inks|printers|inks/})

现在我想您也可以通过文本搜索来做同样的事情。

db.collection.find({$text:{$search : "\"printers inks\" printers inks"}})

注意转义引号。

关于MongoDB 文本搜索和具有词干提取的多个搜索词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46333721/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com