[英]PHP: How to use mysql fulltext search and handle fulltext search result
我試圖在我的Intranet中使用mysql全文搜索。 我想用它在多個表中搜索,並根據結果頁面中的表獲得獨立的結果。
這是我所做的搜索。
$query = "
SELECT *
FROM testtable t1, testtable2 t2, testtable3 t3
WHERE match(t1.firstName, t1.lastName, t1.details) against(' ".$value."')
or match(t2.others, t2.information, t2.details) against(' ".$value."')
or match(t3.other, t2.info, t2.details) against(' ".$value."')
";
$result = mysql_query($query)or die('query error'.mysql_error());
while($row = mysql_fetch_assoc($result)){
echo $row['firstName'];
echo $row['lastName'];
echo $row['details'].'<br />';
}
您是否有關於優化查詢和格式化搜索結果輸出的想法?
您不能在多個表上創建fulltext index
。 因此,我在每個表和or
子句上都找到了fulltext index
(就像您一樣)。
但是,您可以創建一個視圖(基於三個表)並針對該視圖創建全文索引。
編輯:不幸的是您不能在Mysql視圖上創建索引
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.