4

單詞和短語搜索,當我問一個相關的問題之前,並通過海報的建議也創造了這個新問題的跟進:MongoDB的 - 邏輯或使用全文搜索

MongoDB full text search - matching words and exact phrases

在MongoDB中使用全文搜索功能時,特別是在搜索單詞和短語混合時,我遇到了意想不到的結果。

使用上一題的海報提供這個有用的例子...

> 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" } 

前兩種查詢表現爲我所期望的,第一個搜索「時間或延遲或延緩」,而第二「遲到或延遲」。

我現在通過閱讀文檔http://docs.mongodb.org/manual/reference/operator/query/text/#phrases的這一部分了解到,第三個包含短語的查詢將搜索「晚OR延遲AND(」on time「)」。

我的問題是,是否有可能在一個文本查詢中搜索「延遲或延遲」(「準時」)?

回答

0

我梳理了text search上的文檔,恐怕我認爲這是MongoDB 2.6的可能性。 MongoDB的文本搜索支持完全不如完整的全文搜索引擎(例如Solr /使用Lucene文本搜索庫構建的東西)。現在,在文本查詢中不支持布爾運算符,因此您無法將「延遲\」的含義從「(延遲或延遲)和(\」按時\「)」更改爲「延遲」或延遲OR \「按時\」「。可能有一些解決方法涉及存儲代替數組的文本或除文本之外的數組,或與ElasticSearch等全文搜索引擎同步,但我寧願在推薦任何東西之前瞭解更多有關查詢用例的信息解決方案。