文本搜索MongoDB PHP没有结果
我正在尝试搜索集合中的文本字段。这是我的收藏中的一个示例文档:文本搜索MongoDB PHP没有结果,php,mongodb,Php,Mongodb,我正在尝试搜索集合中的文本字段。这是我的收藏中的一个示例文档: { "_id" : ObjectId("51f9c432573906141dbc9996"), "id" : ObjectId("51f9c432573906141dbc9995"), "body" : "the", "rank" : 0, "num_comm" : 0, "activity" : 1375323186 } 这就是我寻找的方式 $mongo = new MongoCl
{
"_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
}
你知道为什么每次我都会得到一个空白的结果数组吗
提前感谢您的帮助
Nathan代码中有嵌套引号(“字符串文字”): 尽量不要嵌套引号
$search_results = $db->command(array('text' => 'trending', 'search' => 'the'));
您不能搜索“the”,因为它是一个停止字,并且停止字没有索引。你可以在以下位置找到停止词列表:
实际上,您可以在调试字符串中看到尝试匹配的内容:
queryDebugString: "||||the||"
第一个元素在这里是空的,这意味着没有匹配完成。如果查看“cat”和“purple”的情况,调试字符串是:
queryDebugString: "cat|purpl||||cat|purple||"
第一个元素现在是cat | purpl
-这表明词干分析也应用于purple
我相信“
是有效的FTS语法。如果您查看PHP手册,其中的语法是错误的。
queryDebugString: "cat|purpl||||cat|purple||"