我想在MySQL中編寫一個布爾全文搜索查詢。但我想有順序的結果:(>
意味着更高)MySQL布爾全文搜索子表達式
Exact Matches
>Including all the words
>Including some of the words
用下面的查詢,我得到確切匹配更高:
SELECT *, MATCH(name,description,address)
AGAINST('>("word1 word2 word3") <(word1 word2 word3)' IN BOOLEAN MODE)
AS score FROM samples WHERE MATCH(name,description,address)
AGAINST('>("word1 word2 word3") <(word1 word2 word3)' IN BOOLEAN MODE) ORDER BY score DESC
通過以下查詢,我得到的文檔包含的所有單詞都高於包含查詢部分內容的單詞:
SELECT *, MATCH(name,description,address)
AGAINST('>(+word1 +word2 +word3) <(word1 word2 word3)' IN BOOLEAN MODE)
AS score FROM samples WHERE MATCH(name,description,address)
AGAINST('>(+word1 +word2 +word3) <(word1 word2 word3)' IN BOOLEAN MODE) ORDER BY score DESC
但我想結合這兩個查詢。這是迄今爲止最好的,但我沒有得到我想要的結果。
SELECT *, MATCH(name,description,address)
AGAINST('>("word1 word2 word3") <(>(+word1 +word2 +word3) <(word1 word2 word3))' IN BOOLEAN MODE)
AS score FROM samples WHERE MATCH(name,description,address)
AGAINST('>("word1 word2 word3") <(>(+word1 +word2 +word3) <(word1 word2 word3))' IN BOOLEAN MODE)
ORDER BY score DESC
有沒有辦法做到這一點沒有UNIONs?
如果有超過2個單詞匹配像'match(..)against('> frist second''),沒有辦法做到這一點。你可能不得不使用'union'。 –