文字索引未按语言返回结果

时间:2019-07-06 12:22:19

标签: mongodb multilingual fulltext-index

我创建了一个收藏链接。 每个文档都有一种现场语言。 当我尝试搜索时,全文搜索无法根据语言进行。

我尝试使用“ it” /“ en”和“ italian / english”(https://docs.mongodb.com/manual/reference/text-search-languages/#text-search-languages) 我尝试使用language_override(https://docs.mongodb.com/manual/tutorial/specify-language-for-text-index/#create-a-text-index-for-a-collection-in-multiple-languages

use search

//Insert some data
db.links.insert({"language": "it", "content": "quando cammino ho male al ginocchio"})
db.links.insert({"language": "it", "content": "ho male alle ginocchia"})
db.links.insert({"language": "en", "content": "A lot of pain knee"})

//Create index
db.links.createIndex({content: "text"})

//Test search but with empty result
db.search.find({$text: {$search: "ginocchia"}})
//I try default english works
db.links.find({$text: {$search: "knee"}})

//So I drop indexes and try language_override
db.links.dropIndexes()
db.search.createIndex({content: "text"}, {language_override: "language"})

//Test search but with empty result
db.search.find({$text: {$search: "ginocchia"}})
//I try default english works
db.links.find({$text: {$search: "knee"}})

//If I set default_language in "it" working in italian and not in english.

我认为,如果我插入“ ginocchia”,则首先获得两个文档,如果我插入“ knee”,则获得最后两个文档。

1 个答案:

答案 0 :(得分:0)

我也在find中使用$ language,现在可以使用