使用Mongodb进行全文搜索

时间:2015-03-06 15:35:42

标签: mongodb

我已经查看了this一段时间,但我想知道我是否可以通过字段进行搜索?

我的集合设置了索引,但在我的集合中,我有字符串,数字和布尔值。

如果我进行了这样的文字搜索:

{ $text: { $search: "false" } }

然后它会发现所有索引字段中都有false,即使false应该是针对一个特定字段的。

理想情况下,我喜欢做类似的事情:

{ $text: { $search: {color:"blue", happy:True, animals:False} } }

颜色,快乐和动物已被编入索引。所以它应该返回包含这些字段组合的所有文档;我可以对它进行排序,并根据哪些文档与最佳文档匹配进行排序。


我们说我的文件是:

{name:"bob", color:"red", happy:True, animals:False}
{name:"smith", color:"blue", happy:False, animals:True}
{name:"joe", color:"blue", happy:True , animals:False}
{name:"jimmy", color:"green", happy:False , animals:True}

如果我搜索过:

{ $text: { $search: {color:"blue", happy:True, animals:False} } }

它会显示:

{name:"joe", color:"blue", happy:True , animals:False}
{name:"bob", color:"red", happy:True, animals:False}
{name:"smith", color:"blue", happy:False, animals:True}

第2行和第3行在顺序方面并不重要,因为它们都符合标准的2/3。

0 个答案:

没有答案