Mysql全文搜索:到where子句,还是不到where子句?

时间:2011-09-20 21:02:37

标签: mysql full-text-search

我有2个mysql全文搜索查询,返回一组不同的结果。

SELECT e.id AS e__id, 
MATCH(e.subtitle, e.summary, e.title, e.prtext) AGAINST ('lorem') 
FROM exhibitions e

将返回一组可预测的7行(我在表中总共有10行),每行包含一个包含单词'lorem'的记录的id。

但是,当我介绍where子句

SELECT e.id 
FROM exhibitions e 
WHERE MATCH(e.subtitle, e.summary, e.title, e.prtext) AGAINST ('lorem')

不返回任何行。

这两个查询之间有什么区别?

2 个答案:

答案 0 :(得分:0)

尝试添加* IN BOOLEAN MODE

SELECT *,MATCH (ft_search_field) AGAINST ('lorem*' IN BOOLEAN MODE) AS Score
FROM table_name
WHERE MATCH (ft_search_field) AGAINST ('lorem*' IN BOOLEAN MODE)

答案 1 :(得分:0)

实际上,问题是我的表结构上有很多全文索引,当时我真的只需要一个。这是一个带有whereand子句的正确查询:

SELECT  e.id AS e__id,
    e.enabled AS e__enabled,
    e.rewrite AS e__rewrite,
    e.title AS e__title,
    e.subtitle AS e__subtitle,
    e.summary AS e__summary,
    e.type AS e__type,
    e.feature_home AS e__feature_home,
    e.date_start AS e__date_start,
    e.date_end AS e__date_end,
    e.prtext AS e__prtext,
    e.last_update AS e__last_update,
    e.file_id1 AS e__file_id1,
    e.file_id2 AS e__file_id2,
    e.file_id3 AS e__file_id3,
    e.file_id4 AS e__file_id4,
    e.file_id5 AS e__file_id5
FROM exhibitions e
WHERE  MATCH(e.subtitle, e.summary, e.title, e.prtext) AGAINST ('lorem')
       AND e.enabled = 1