MongoDB - 使用全文搜索搜索单词和短语时的逻辑或 [英] MongoDB - Logical OR when searching for words and phrases using full text search

查看:119
本文介绍了MongoDB - 使用全文搜索搜索单词和短语时的逻辑或的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

之前我问过一个相关的问题,正如海报所建议的那样,我们已经创建了这个新问题作为后续工作:

MongoDB全文搜索 - 匹配单词和确切短语



在MongoDB中使用全文搜索功能时,特别是在搜索单词和短语的混合时,我遇到了意想不到的结果。



使用前面问题中海报提供的有用示例...

 > db.test.drop()
> db.test.insert({t:我准时,不迟到或延迟})
> db.test.insert({t:我要么迟到,要么延迟})
> db.test.insert({t:Time like a banana})
> db.test.ensureIndex({t:text})

> db.test.find({$ text:{$ search:time late delay}},{_id:0})
{t:我准时,不迟到或延迟}
{t:时间飞得像香蕉一样}
{t:我要么迟到,要么迟到}

> db.test.find({$ text:{$ search:late delay}},{_id:0})
{t:我准时,不是迟到或延迟}
{t:我要么迟到,要么迟到}

> db.test.find({$ text:{$ search:late delay \on time \}},{_id:0})
{t: 我准时,没迟到或延迟}

前两个查询的行为与我的行为相同预计,第一次搜索时间或延迟或延迟,第二次搜索延迟或延迟。

我现在通过阅读本节 http://docs.mongodb.org/manual/reference/operator/query / text /#phrase ,第三个包含短语的查询将搜索延迟或延迟AND(on time)。

我的问题是,是否可以在一个文本查询中搜索延迟或延迟(准时)?

解决方案

我在文本搜索上梳理了文档,恐怕我不认为这是可能从MongoDB 2.6开始。 MongoDB的文本搜索支持完全不如完整的全文搜索引擎(例如Solr /使用Lucene文本搜索库构建的东西)。现在,在文本查询中不支持布尔操作符,因此您无法在time \从(延迟或延迟)和(\on time \)上更改延迟延迟\\的含义。 按时或延迟或延迟。可能有一些解决方法涉及存储代替数组的文本或除文本外,或与ElasticSearch等全文搜索引擎同步,但我宁愿在推荐任何东西之前了解更多关于查询用例的信息解决方案。

I asked a related question previously, and as suggested by the poster there have created this new question as a follow up:

MongoDB full text search - matching words and exact phrases

I was having some problems with unexpected results when using the full text search functionality in MongoDB, specifically when searching for a mixture of words and phrases.

Using this helpful example provided by the poster in the previous question...

> db.test.drop()
> db.test.insert({ "t" : "I'm on time, not late or delayed" })
> db.test.insert({ "t" : "I'm either late or delayed" })
> db.test.insert({ "t" : "Time flies like a banana" })
> db.test.ensureIndex({ "t" : "text" })

> db.test.find({ "$text" : { "$search" : "time late delay" } }, { "_id" : 0 })
{ "t" : "I'm on time, not late or delayed" }
{ "t" : "Time flies like a banana" }
{ "t" : "I'm either late or delayed" }

> db.test.find({ "$text" : { "$search" : "late delay" } }, { "_id" : 0 })
{ "t" : "I'm on time, not late or delayed" }
{ "t" : "I'm either late or delayed" }

> db.test.find({ "$text" : { "$search" : "late delay \"on time\"" } }, { "_id" : 0 })
{ "t" : "I'm on time, not late or delayed" }

The first two queries behave as I would expect, the first searching for "time OR late OR delay" and the second for "late OR delay".

I now understand from reading this section of the documentation http://docs.mongodb.org/manual/reference/operator/query/text/#phrases that the third query, which includes a phrase will search for "late OR delay AND ("on time")".

My question is, is it possible to search for "late OR delay OR ("on time")" in one text query?

解决方案

I combed the docs on text search, and I'm afraid I don't think this is possible as of MongoDB 2.6. MongoDB's text search support is simply not as complete as a bona fide full text search engine (e.g. Solr/things built with the Lucene text search library). Right now, there's no support for boolean operators in text queries, so you cannot change the meaning of "late delay \"on time\"" from "(late OR delay) AND (\"on time\")" to "late OR delay OR \"on time\"". There might be some workarounds involving storing an array of tokens instead of or in addition to the text, or synchronizing with a full text search engine like ElasticSearch, but I'd rather know a bit more about the use case for the query before recommending any solutions.

这篇关于MongoDB - 使用全文搜索搜索单词和短语时的逻辑或的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆