我曾尝试在我的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 />';
}
您对优化查询和格式化搜索结果的输出有什么想法吗?
答案 0 :(得分:0)
您无法在多个表格上创建fulltext index
。所以我在每个表上找到fulltext index
,并且or
条款(就像你一样)足够好。
但是,您可以创建一个视图(基于三个表)并针对该视图创建全文索引。
编辑:不幸的是你无法在Mysql中的视图上创建索引