[英]Mysql fulltext search: To where clause, or not to where clause?
我有2個mysql全文搜索查詢,它們返回不同的結果集。
SELECT e.id AS e__id,
MATCH(e.subtitle, e.summary, e.title, e.prtext) AGAINST ('lorem')
FROM exhibitions e
將返回一組可預測的7行(表中總共10行),每行的記錄ID均包含“ lorem”一詞。
但是,當我引入where子句時
SELECT e.id
FROM exhibitions e
WHERE MATCH(e.subtitle, e.summary, e.title, e.prtext) AGAINST ('lorem')
不返回任何行。
這兩個查詢有什么區別?
嘗試在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)
實際上,問題是我的表結構上有很多全文索引,而我實際上只需要一個。 這是帶有where
和and
子句的正確查詢:
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.