首页 > 解决方案 > MongoDB 全文搜索不适用于特定单词(不是停用词)

问题描述

我有一个带有 MongoDB 4.4.x 和 PHP7.x 的 VPS,并使用 MongoDB PHP 库与 MongoDB 连接。

我的文件(大约 1000 万份)如下所示:

集合:租户,answers.answer 上的全文索引

"survey_id": {
    "$numberLong": "424221"
},
"account_id": 20014,
"feedback_id": 738857,
"date_reg": "2021-04-22",
"time_reg": "21:15",
"source": 2,
"trigg": 1,
"read_status": 0,
.... etc...,
"answers": {
    "0": {
        "answer": "Feedback answer 1 lorem ipsum gmail doramet",
        "type": 1,
        "qid": 4241,
        "datatype": 24,
        "additional": "",
        "q": "What do you think about..."
    },
    "1": {
        "answer": "Feedback answer steve lorem ipsum",
        "type": 2,
        "qid": 21,
        "datatype": 2,
        "additional": "",
        "q": "What was your experience with..."
    },
   ... etc...

然后我像这样搜索:

$manager = new 
MongoDB\Driver\Manager("mongodb://user:pass@localhost:27017");
$filter = ['$text' => ['$search' => "steve"]];
$options = ['limit' => 10];
$query = new MongoDB\Driver\Query($filter,$options);
$cursor = $manager->executeQuery('db.tenants', $query);

foreach($cursor as $row){
  
  echo '<pre>';
  print_r($row);
  echo '</pre><br><br>';
  
  
  $i++;

  }

这不会返回带有“史蒂夫”的答案。但是,如果我搜索确实有效的“gmail”。那么为什么不为“史蒂夫”呢?两者都不是停用词。我究竟做错了什么?

标签: phpmongodbmongodb-queryfull-text-searchfull-text-indexing

解决方案


推荐阅读