MongoDB 停用词文本搜索失败
MongoDB Text search fails for stop words
我正在尝试在我的 collection 中进行查询,但它没有返回任何内容。
这是我的 query
:
{'$match': {'$text': {'$search': 'a'}}},
{'$group': {'_id': {'texto': '$texto'},
'somanumero': {'$sum': '$numero'}}}
我的collection:
{ "_id" : ObjectId("555cdc4fe13823315537042d"), "texto" : ObjectId("555cdc4fe13823315537042c"), "numero" : ObjectId("555cdc4fe13823315537042e") }
{ "_id" : ObjectId("555cdc5ee13823315537042f"), "numero" : 5, "texto" : "a", "lattexto" : "-15.79506", "lontexto" : "-47.88322" }
{ "_id" : ObjectId("555cdc6ae138233155370430"), "numero" : 10, "texto" : "a", "lattexto" : "-15.79506", "lontexto" : "-47.88322" }
{ "_id" : ObjectId("555cdc73e138233155370431"), "numero" : 3, "texto" : "b", "lattexto" : "-15.79506", "lontexto" : "-47.88322" }
这是我的文本索引:
{
"v" : 1,
"key" : {
"_fts" : "text",
"_ftsx" : 1
},
"name" : "texto_text",
"ns" : "OSA.teste_texto",
"default_language" : "portuguese",
"weights" : {
"texto" : 1
},
"language_override" : "language",
"textIndexVersion" : 2
}
当我单独使用 $group
或 $match
时,它有效。
我是不是做错了什么?
来自docs:
MongoDB supports text search for various languages. text indexes drop
language-specific stop words (e.g. in English, “the”, “an”, “a”,
“and”, etc.) and uses simple language-specific suffix stemming.
您的数据存在问题,部分记录具有 language-specific
停用词 a
,这在 portugese 中也被视为停用词。一些停用词包括 a
位于列表顶部。
a
ao
aos
aquela
aquelas
aquele
aqueles
aquilo
as
até
com
como
这些词 从未 编入索引,因此无论何时查询停用词,都不会得到任何结果。
同时,如果您查询 b
,您会得到结果,因为它不是停用词并且会被编入索引。
我正在尝试在我的 collection 中进行查询,但它没有返回任何内容。
这是我的 query
:
{'$match': {'$text': {'$search': 'a'}}},
{'$group': {'_id': {'texto': '$texto'},
'somanumero': {'$sum': '$numero'}}}
我的collection:
{ "_id" : ObjectId("555cdc4fe13823315537042d"), "texto" : ObjectId("555cdc4fe13823315537042c"), "numero" : ObjectId("555cdc4fe13823315537042e") }
{ "_id" : ObjectId("555cdc5ee13823315537042f"), "numero" : 5, "texto" : "a", "lattexto" : "-15.79506", "lontexto" : "-47.88322" }
{ "_id" : ObjectId("555cdc6ae138233155370430"), "numero" : 10, "texto" : "a", "lattexto" : "-15.79506", "lontexto" : "-47.88322" }
{ "_id" : ObjectId("555cdc73e138233155370431"), "numero" : 3, "texto" : "b", "lattexto" : "-15.79506", "lontexto" : "-47.88322" }
这是我的文本索引:
{
"v" : 1,
"key" : {
"_fts" : "text",
"_ftsx" : 1
},
"name" : "texto_text",
"ns" : "OSA.teste_texto",
"default_language" : "portuguese",
"weights" : {
"texto" : 1
},
"language_override" : "language",
"textIndexVersion" : 2
}
当我单独使用 $group
或 $match
时,它有效。
我是不是做错了什么?
来自docs:
MongoDB supports text search for various languages. text indexes drop language-specific stop words (e.g. in English, “the”, “an”, “a”, “and”, etc.) and uses simple language-specific suffix stemming.
您的数据存在问题,部分记录具有 language-specific
停用词 a
,这在 portugese 中也被视为停用词。一些停用词包括 a
位于列表顶部。
a
ao
aos
aquela
aquelas
aquele
aqueles
aquilo
as
até
com
como
这些词 从未 编入索引,因此无论何时查询停用词,都不会得到任何结果。
同时,如果您查询 b
,您会得到结果,因为它不是停用词并且会被编入索引。