douchi5822 2017-02-08 06:43
浏览 36

MySQL Show相关查询无法正常工作

I have a query that shows the related videos of the current video based on the title and the tags I am playing. The thing is it doesn't really show related videos even when the names are exactly the same.

Here is the code and query.

$pieces = array_filter(explode(" ", removeCommonWords(str_replace(array('(', ')'), '', $video->title))));
$pieces2 = array_filter(explode(",", removeCommonWords(str_replace(array('(', ')'), '', $video->tags))));
$pieces = array_merge($pieces, $pieces2);
$par = array();
$par[] = removeCommonWords(str_replace(array('(', ')'), '', $video->title));
foreach($pieces as $p) {
    if (strlen($p) > 2) {
        if (strlen($p) < 4) {
            $par[] = $p.
            '*';
        } else {
            $par[] = $p;
        }
    }
}
$key = toDb(implode(",", $par));
$options = DB_PREFIX.
"videos.id as vid,".DB_PREFIX.
"videos.title,".DB_PREFIX.
"videos.user_id as owner,".DB_PREFIX.
"videos.thumb,".DB_PREFIX.
"videos.views,".DB_PREFIX.
"videos.duration";
$vq = "select ".$options.
", ".DB_PREFIX.
"users.name ,
MATCH(title, description, tags) AGAINST('".$key."'
        IN BOOLEAN MODE) AS relevance,
    MATCH(title) AGAINST('".$key."'
        IN BOOLEAN MODE) AS title_relevance FROM ".DB_PREFIX."
videos LEFT JOIN ".DB_PREFIX."
users ON ".DB_PREFIX."
videos.user_id = ".DB_PREFIX."
users.id
WHERE MATCH(title, description, tags) AGAINST('".$key."'
    IN BOOLEAN MODE) AND ".DB_PREFIX."
videos.pub > 0 ORDER by title_relevance DESC, relevance DESC limit 1, ".get_option('related-nr',12)."
";
$result = $cachedb->get_results($vq);

Is there anything am I missing?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
    • ¥20 西门子S7-Graph,S7-300,梯形图
    • ¥50 用易语言http 访问不了网页
    • ¥50 safari浏览器fetch提交数据后数据丢失问题
    • ¥15 matlab不知道怎么改,求解答!!
    • ¥15 永磁直线电机的电流环pi调不出来
    • ¥15 用stata实现聚类的代码
    • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
    • ¥20 docker里部署springboot项目,访问不到扬声器
    • ¥15 netty整合springboot之后自动重连失效