douyinghuo8874 2018-08-30 10:00
浏览 107

在MongoDB和Laravel中搜索全文

I want to do a full text search on the mongo database. This is my code in 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;
    }

This method in Repository

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

This is index in collection Videos on my db

> 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
    }
]

As a result, when searching, I find objects by fields but I can not do it like "Like" in mysql

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微带串馈天线阵列每个阵元宽度计算
    • ¥15 keil的map文件中Image component sizes各项意思
    • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 Centos / PETGEM
    • ¥15 划分vlan后不通了
    • ¥20 用雷电模拟器安装百达屋apk一直闪退