简体   繁体   English

PHP:如何使用mysql全文搜索和处理全文搜索结果

[英]PHP: How to use mysql fulltext search and handle fulltext search result

I have tried to use mysql fulltext search in my intranet. 我试图在我的Intranet中使用mysql全文搜索。 I wanted to use it to search in multiple tables, and get the independant results depending on tables in the result page. 我想用它在多个表中搜索,并根据结果页面中的表获得独立的结果。

This is what i did for searching. 这是我所做的搜索。

$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 />';
}

Do you have any ideas about optimizing the query and format the output of search results? 您是否有关于优化查询和格式化搜索结果输出的想法?

You can not create a fulltext index on a several tables. 您不能在多个表上创建fulltext index So I find a fulltext index on each table and or clauses (just like you do) good enough. 因此,我在每个表和or子句上都找到了fulltext index (就像您一样)。

However you can create a view (based on the three tables) and create the fulltext index against that view. 但是,您可以创建一个视图(基于三个表)并针对该视图创建全文索引。

EDIT: Unfortunately you can not create an index on a view in Mysql 编辑:不幸的是您不能在Mysql视图上创建索引

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM