douji5329 2016-10-28 06:22
浏览 43

在mongodb中搜索全文

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

Outputs:

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

Using:

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

Outputs:

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

Using:

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

Outputs:

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

But when I try :

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

Output:

0

I am expecting a different output, what is wrong?

  • 写回答

2条回答 默认 最新

  • doupingyun73833 2016-10-28 07:31
    关注

    Mongodb has some stop words for $text operator.

    Stop Words

    The $text operator ignores language-specific stop words, such as the and and in English.

    Since you are using one of the stop word, in the query db.collection.find({'$text':{'$search':"The"}}) and hence it is not returning any results.

    References:

    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

    评论

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥15 Oracle触发器记录修改前后的字段值
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题