我有一个mysql全文问题。参考:http://dev.mysql.com/doc/refman/5.0/en/fulltext-boolean.html
SELECT * FROM table WHERE (MATCH (aindex,bindex) AGAINST ('(+apple +juice)' IN BOOLEAN MODE))
此返回14项
SELECT * FROM table WHERE (MATCH (aindex,bindex) AGAINST ('(+apple +pie)' IN BOOLEAN MODE))
此返回36项
SELECT * FROM table WHERE (MATCH (aindex,bindex) AGAINST ('(+apple +pie)|(+apple +juice)' IN BOOLEAN MODE))
此返回1910项,显然,我的查询有问题。如何搜索确切包含(+apple +pie)
和(+apple +juice)
的字词?我认为应该返回14+36=50items
在我的目的中,我需要联合搜索
(+apple +pie) (+apple +juice) (+apple +macintosh) (+apple +turnover) (+apple +strudel) (+pear +pie) (+pear +juice) (+pear +macintosh) (+pear +turnover) (+pear +strudel)
它应该返回近520项。感谢。
答案 0 :(得分:2)
这应该是你想要的:
SELECT
*
FROM
table
WHERE
(MATCH (aindex,bindex) AGAINST ('+apple +(pie juice)' IN BOOLEAN MODE))
ETA:错过了我第一次阅读的梨条款。要获得您列出的所有内容,我认为这应该有效:
SELECT
*
FROM
table
WHERE
(MATCH (aindex,bindex) AGAINST ('+((apple +(pie juice macintosh turnover strudel)) (pear +(pie juice macintosh turnover strudel)))' IN BOOLEAN MODE));
这应该转化为“必须包含苹果和馅饼,果汁,macintosh,营业额或馅饼或梨以及馅饼,果汁,麦金托什,营业额或馅饼之一。
如果这不起作用,我会这样做:
SELECT
*
FROM
table
WHERE
(MATCH (aindex,bindex) AGAINST ('+apple +(pie juice macintosh turnover strudel)' IN BOOLEAN MODE))
UNION
SELECT
*
FROM
table
WHERE
(MATCH (aindex,bindex) AGAINST ('+pear +(pie juice macintosh turnover strudel)' IN BOOLEAN MODE));