2009-11-24 56 views
0

我有類似如下的MySQL查詢:如何增加高級MySQL查詢中的相關性值?

SELECT *, MATCH (`Description`) AGAINST ('+ipod +touch ' IN BOOLEAN MODE) * 8 + MATCH(`Description`) AGAINST ('ipod touch' IN BOOLEAN MODE) AS Relevance 
FROM products WHERE (MATCH (`Description`) AGAINST ('+ipod +touch' IN BOOLEAN MODE) OR MATCH(`LongDescription`) AGAINST ('+ipod +touch' IN BOOLEAN MODE)) 
HAVING Relevance > 1 
ORDER BY Relevance DESC 

現在,我所做的查詢也通過搜索UPC更先進:

SELECT *, MATCH (`Description`) AGAINST ('+ipod +touch ' IN BOOLEAN MODE) * 8 + MATCH(`Description`) AGAINST ('ipod touch' IN BOOLEAN MODE) + `UPC` = '123456789012' * 16 AS Relevance 
FROM products WHERE (MATCH (`Description`) AGAINST ('+ipod +touch' IN BOOLEAN MODE) OR MATCH(`LongDescription`) AGAINST ('+ipod +touch' IN BOOLEAN MODE)) AND `UPC` = '123456789012' 
HAVING Relevance > 1 
ORDER BY Relevance DESC 

那將返回結果,但是我在UPC上獲得了成功的比賽並不會增加價值Relevance。我只能進行像MATCH()AGAINST()這樣的全文搜索的計算嗎?

澄清:好的,所以我真正的問題是,爲什麼以下沒有相關性> = 16?

SELECT `UPC`, `UPC` = '123456789012' * 16 AS Relevance FROM products WHERE `UPC` = '123456789012' HAVING Relevance > 1 ORDER BY Relevance DESC 

回答

0

首先,我認爲這是多餘的SELECT再次使用UPC = '123455778'。你不會得到任何不是真的行,那麼爲什麼不使用「1」呢?

話雖如此,我認爲你的問題是操作的順序。括號中的括號比較適用於我:

SELECT 
    `UPC`, 
    (`UPC` = '12346790') * 16 AS Relevance 
FROM 
    `products` 
WHERE 
    `UPC` = '12346790' 
HAVING 
    Relevance > 1 
ORDER BY 
    Relevance DESC