【问题标题】:Mysql fulltext search: To where clause, or not to where clause?Mysql全文搜索:到where子句,还是不到where子句?
【发布时间】:2011-09-20 21:02:36
【问题描述】:

我有 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')

不返回任何行。

这两个查询有什么区别?

【问题讨论】:

    标签: mysql full-text-search


    【解决方案1】:

    尝试在布尔模式下添加 *

    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)
    

    【讨论】:

      【解决方案2】:

      实际上,问题在于我的表结构上有许多全文索引,而我真的只需要一个。这是带有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
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-10-13
        • 2019-10-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多