[英]No Results with Text Search MongoDB PHP
我试图在我的收藏中搜索一个文本字段。 这是我收藏中的示例文档:
{
"_id" : ObjectId("51f9c432573906141dbc9996"),
"id" : ObjectId("51f9c432573906141dbc9995"),
"body" : "the",
"rank" : 0,
"num_comm" : 0,
"activity" : 1375323186
}
这就是我的搜索方式...
$mongo = new MongoClient("mongodb://127.0.0.1");
$db = $mongo->requestry;
try
{
$search_results = $db->command(array('text' => 'trending', 'search' => '"the"'));
}
catch (MongoCursorException $e)
{
return array('error' => true, 'msg' => $e->getCode());
}
return array('error' => false, 'results' => $search_results);
这就是我得到的结果...
{
error: false,
results: {
queryDebugString: "||||the||",
language: "english",
results: [ ],
stats: {
nscanned: 0,
nscannedObjects: 0,
n: 0,
nfound: 0,
timeMicros: 66
},
ok: 1
}
}
以下是我对该系列的索引...
{
"v" : 1,
"key" : {
"_id" : 1
},
"ns" : "requestry.trending",
"name" : "_id_"
},
{
"v" : 1,
"key" : {
"_fts" : "text",
"_ftsx" : 1
},
"ns" : "requestry.trending",
"name" : "body_text",
"weights" : {
"body" : 1
},
"default_language" : "english",
"language_override" : "language",
"textIndexVersion" : 1
}
关于为什么每次都会得到空白结果数组的任何想法?
在此先感谢您的帮助!
内森
您不能搜索“ the”,因为它是一个停用词,并且停用词未编制索引。 您可以在https://github.com/mongodb/mongo/blob/master/src/mongo/db/fts/stop_words_english.txt中找到停用词列表
您实际上可以在调试字符串中看到尝试匹配的内容:
queryDebugString: "||||the||"
第一个元素在此处为空,这意味着不进行匹配。 如果您查看'"cat" AND "purple"'
,则调试字符串为:
queryDebugString: "cat|purpl||||cat|purple||"
现在第一个元素是cat|purpl
这表明词干也已应用于purple
。
您在代码(“ the”字符串文字)上嵌套了引号:
$search_results = $db->command(array('text' => 'trending', 'search' => '"the"'));
尽量不要嵌套引号
$search_results = $db->command(array('text' => 'trending', 'search' => 'the'));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.