1

我正在使用此查询,但不幸的是它运行缓慢:

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。

4

1 回答 1

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)
于 2012-04-15T18:54:09.970 回答