Text search query for text “other” always returns no results?

后端 未结 3 807
生来不讨喜
生来不讨喜 2021-01-23 18:45

My data looks like this:

[{\"id\" : 1, \"question\" : \"Other specified dermatomycoses\", ... },
 {\"id\" : 6, \"question\" : \"Other specified disorders of join         


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-23 19:05

    When creating a text index in MongoDB, if you do not specify a language value it will use english by default and its stop words. If you want to be able to search by the stop words you will have to set the default language value of your text index to "none".

    Create your index like this:

    db.questions.createIndex({ theSearchField : 'text' }, { default_language: 'none' })
    

    Then you should be able to run your query

    db.questions.find({$text:{$search:'other'}}).count()
    

提交回复
热议问题