我正在使用此查询,但遗憾的是它运行缓慢:
SELECT *,
(MATCH(`title`) AGAINST ('$word' IN BOOLEAN MODE) * 2
+ MATCH(`content`) AGAINST ('$word' IN BOOLEAN MODE) * 2
+ MATCH(`url`) AGAINST ('$word' IN BOOLEAN MODE) * 1.1
+ MATCH(`desc`) AGAINST ('$word' IN BOOLEAN MODE) * 1.2) * `like`
AS score
FROM `data`
WHERE MATCH(`content`,`desc`,`title`,`url`) AGAINST ('$word' IN BOOLEAN MODE)
ORDER BY `score` DESC LIMIT 1000
数据库的结果是15000.这意味着将完成15000条记录,但查询时间大约需要25秒。我正在使用PDO。
答案 0 :(得分:0)
您将需要FULLTEXT索引,否则DBMS将需要每次都搜索整个表。这确实减慢了记录的插入速度。请注意,对4列进行全文搜索总是相对较慢。
CREATE FULLTEXT INDEX indexTitle ON `data` (title)
CREATE FULLTEXT INDEX indexContent ON `data` (content)
CREATE FULLTEXT INDEX indexURL ON `data` (url)
CREATE FULLTEXT INDEX indexDesc ON `data` (desc)
CREATE FULLTEXT INDEX combinedIndex ON `data` (content, desc, title, url)