在MongoDB和Laravel中搜索全文

时间:2018-08-30 10:00:50

标签: php mongodb laravel search text

我想在mongo数据库上进行全文搜索。这是我在Service中的代码

 public function search(array $params = [])
    {
        $search_query = $this->getFromArr($params, 'search_query');
        $limit = $this->getFromArr($params, 'limit');
        $videoList = $this->videos->findByPhase($search_query, $limit);
        return $videoList;
    }

存储库中的此方法

public function findByPhase($phase, $limit)
{
    return $this->model->whereRaw(['$text' => ['$search' => $phase]])->paginate(intval($limit));
}

这是我数据库上收藏的视频中的索引

> db.videos.getIndexes()
[
    {
        "v" : 2,
        "key" : {
            "_id" : 1
        },
        "name" : "_id_",
        "ns" : "vod_app.videos"
    },
    {
        "v" : 2,
        "key" : {
            "_fts" : "text",
            "_ftsx" : 1
        },
        "name" : "recipe_full_text",
        "weights" : {
            "description" : 12,
            "title" : 32
        },
        "ns" : "vod_app.videos",
        "default_language" : "english",
        "language_override" : "language",
        "textIndexVersion" : 3
    }
]

结果,在搜索时,我可以按字段查找对象,但不能像mysql中的“ Like”一样

0 个答案:

没有答案