Heim  >  Artikel  >  Backend-Entwicklung  >  PHP+MYSQL 多关键词+模糊搜索+匹配度排序,请问如何实现

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

WBOY
WBOYOriginal
2016-06-13 12:53:241030Durchsuche

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)

------解决方案--------------------
若要计算匹配度,也只需
select sign(LOCATE('中国',a.`title`))+sign(LOCATE('北京',a.`title`))+sign(LOCATE('天安门',a.`title`)) as 匹配数 from ...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn