MySQL全文搜索运行得如此之慢

时间:2013-11-29 10:02:29

标签: php mysql full-text-search

我编写代码来搜索不同表中的关键字。这是我的代码:

$stmt = $conn->prepare("SELECT DISTINCT rest.*,
MATCH(rest.resname, rest.address) AGAINST(:keyword) as a,
MATCH(cuisine.cuisine) AGAINST(:keyword) as b,
MATCH(recc.recc) AGAINST(:keyword) as c,
MATCH(emenu.menu, emenu.menudesc) AGAINST(:keyword) as d,
MATCH(facilities.fac) AGAINST(:keyword) as e,
MATCH(serv.service) AGAINST(:keyword) as f
FROM rest
INNER JOIN cuisine ON rest.resID = cuisine.resID
INNER JOIN recc ON rest.resID = recc.resID
INNER JOIN emenu ON rest.resID = emenu.resID
INNER JOIN facilities ON rest.resID = facilities.resID
INNER JOIN serv ON rest.resID = serv.resID
WHERE
(
MATCH(rest.resname, rest.address) AGAINST(:keyword)
OR MATCH(cuisine.cuisine) AGAINST(:keyword)
OR MATCH(recc.recc) AGAINST(:keyword)
OR MATCH(emenu.menu, emenu.menudesc) AGAINST(:keyword)
OR MATCH(facilities.fac) AGAINST(:keyword)
OR MATCH(serv.service) AGAINST(:keyword)
)
AND (aktif = :aktif) AND (negeri = :negeri) GROUP BY resID ORDER BY resID DESC LIMIT :rowsperpage OFFSET :offset");

$stmt->bindValue(':keyword', $_GET["keyword"], PDO::PARAM_STR);
$stmt->bindValue(':negeri', $negeri, PDO::PARAM_STR);
$stmt->bindValue(':aktif', $active, PDO::PARAM_STR);
$stmt->bindValue(':rowsperpage', (int) $rowsperpage, PDO::PARAM_INT);
$stmt->bindValue(':offset', (int) $offset, PDO::PARAM_INT);
$stmt->execute();

此查询涉及6个表。

当我运行它时,搜索运行速度很慢。

你能告诉我怎么解决这个问题吗?以及如何在phpMyAdmin表中创建索引?

0 个答案:

没有答案