簡體   English   中英

在mongodb中搜索全文

[英]Search full text in mongodb

db.collection.createIndex({"type_name":"text"});
db.collection.find();

輸出:

{ "type_id" : "10735", "type_name" : "Tycho" }

{ "type_id" : "1550", "type_name" : "Trina" }

{ "type_id" : "12925", "type_name" : "Tiffany" }

{ "type_id" : "1637", "type_name" : "The Wombats" }

{ "type_id" : "11470", "type_name" : "The Wanted" }

使用方法:

db.collection.find({'$text':{'$search':"The Wombats"}})

輸出:

{ "type_id" : "1637", "type_name" : "The Wombats" }

使用方法:

db.collection.find({'$text':{'$search':"Wombats"}});

輸出:

{ "type_id" : "1637", "type_name" : "The Wombats" }

但是當我嘗試:

db.collection.find({'$text':{'$search':"The"}});

輸出:

0

我期望輸出不同,這是怎么回事?

Mongodb為$ text運算符提供了一些停用詞。

停用詞

該文$操作忽略特定語言的停用詞, 英文。

由於您使用的是停用詞之一,因此在查詢db.collection.find({'$text':{'$search':"The"}}) ,因此不會返回任何結果。

參考文獻:

https://docs.mongodb.com/v3.2/reference/operator/query/text/#op._S_text

https://docs.mongodb.com/v3.2/reference/operator/query/text/#match-operation

但是當我嘗試這個

$ regex = new MongoRegex(“ / ^”。the。“ ^ /”。“ / i”);

$ artistNmaeRenge = array('type_name'=> $ regex); 它正在工作

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM