Home > Backend Development > PHP Tutorial > PHP+MYSQL 多关键词+模糊搜索+匹配度排序,请问如何实现

PHP+MYSQL 多关键词+模糊搜索+匹配度排序,请问如何实现

WBOY
Release: 2016-06-13 12:53:24
Original
1075 people have browsed it

PHP+MYSQL 多关键词+模糊搜索+匹配度排序,请教怎么实现?
已经用MYSQL 的 UNION 实现了一个,但是效率太差,请教论坛上的高人有没有更好的方法。

mysql php 模糊搜索 排序
------解决方案--------------------
既然你不需要计算出现的次数,那么合起来不是更好
SELECT a.`askid`,a.`catid`,a.`title`,a.`status`,a.`addtime`,a.`reward`,a.`answercount`,b.`message` <br />
 FROM `phpcms_ask` a LEFT JOIN `phpcms_ask_posts` b ON a.`askid`=b.`askid`<br />
 WHERE (a.status=3 OR a.status=5) AND b.`isask`=1 AND (LOCATE('中国',a.`title`)>0 OR LOCATE('北京',a.`title`)>0 OR LOCATE('天安门',a.`title`)>0)
Copy after login

------解决方案--------------------
若要计算匹配度,也只需
select sign(LOCATE('中国',a.`title`))+sign(LOCATE('北京',a.`title`))+sign(LOCATE('天安门',a.`title`)) as 匹配数 from ...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template