Hello!

Please help me with the full text index in MongoDB.

> db.ftsc.insert({"name":"10pisem+1"}); > db.ftsc.insert({"name":"20pisem+1"}); > db.ftsc.insert({"name":"20pisem 2 письма"}); > db.ftsc.insert({"name":"20pisem 2 письмо"}); > > db.ftsc.ensureIndex({"name":"text"}); > > db.ftsc.find( { $text: { $search: "письм" } } ); // результат 0, хотя я ожидал 2 записи > > db.ftsc.find( { $text: { $search: "письмо" } } ); { "_id" : ObjectId("53ba8e56fd2bc6bd8af53531"), "name" : "20pisem 2 письмо" } > > db.ftsc.find( { $text: { $search: "pis" } } ); // результат 0 > > db.ftsc.find( { $text: { $search: "1" } } ); { "_id" : ObjectId("53ba8e35fd2bc6bd8af5352f"), "name" : "20pisem+1" } { "_id" : ObjectId("53ba8e23fd2bc6bd8af5352e"), "name" : "10pisem+1" } > > db.ftsc.find( { $text: { $search: "10" } } ); //результат 0 > > db.ftsc.find( { $text: { $search: "m+1" } } ); { "_id" : ObjectId("53ba8e35fd2bc6bd8af5352f"), "name" : "20pisem+1" } { "_id" : ObjectId("53ba8e23fd2bc6bd8af5352e"), "name" : "10pisem+1" } > > db.ftsc.find( { $text: { $search: "m+" } } ); // результат 0 

How to properly adjust the index, what would it look for by occurrences of the substring?

PS: do not use regular expressions.

    1 answer 1

    Depends on your mongo version. If it is under 2.6 (or 2.4, I don’t remember), then you need to turn on the search by hand.

     mongod --setParameter textSearchEnabled=true 

    Also, according to the standard there is not Russian. If not done so -

     db.collection.ensureIndex( { name: "text" }, { default_language: "russian" }) 

    And in general, to you here - Full - text search in MongoDB

    • @Vladimir Vasyukov - Yes, I read all this, the parameters are included. As for the Russian, this is one question, and this is why he is not looking here with this parameter:> db.ftsc.find ({$ text: {$ search: "pis"}}); // result 0 is unclear. When you install the Russian language for the request "letter" also does not look for anything. - Opalosolo