PHP搜索引擎关键词排名 [英] php search engine key words ranking

查看:128
本文介绍了PHP搜索引擎关键词排名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是php和mysql的新手.在我的项目中,我必须为多个列上的多个关键字开发搜索引擎,并且还需要关键字排名和相关性.

I am new to php and mysql. In my project I have to develop search engine for multiple keywords on multiple columns and also require the keyword ranking and relevency.

例如,如果我有三个单词嗨",你好",嘿",并且想要搜索诸如主题,消息,参考,文本正文之类的字段.在这种情况下,关键字排名较高的行将排在第一位,排名最低的行排在最后.有谁能指导我如何实施这样的搜索引擎.我的数据库大约有400万,并且正在快速增长.

For example if I have three words hello, hey and want to search on fields like subject, message, reference, textbody. in this case the row who has more keywords ranking will come first and lowest ranker row goes last. will any one guide me how to implement such search engine. my database is about 4 million and is growing rapidly.

推荐答案

使用全文本搜索:

<?PHP

    //SET THE SEARCH TERM
    $term = "Search Term";


    $sql = "SELECT *, MATCH(subject, message,reference,textbody) AGAINST('". $term ."') as score FROM pages WHERE MATCH (subject, message,reference,textbody) AGAINST('". $term ."') ORDER BY score DESC";
    $query = mysql_query($sql);

    //BUILD A LIST OF THE RESULTS
    while($result = mysql_fetch_assoc($query)) {
       // your stuff for showing result
    }

?>

注意:您应该在主题,消息,引用,文本正文的列上具有FULLTEXT索引

Note: you should have FULLTEXT indexing on the columns subject, message,reference,textbody

这篇关于PHP搜索引擎关键词排名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆