下令這個問題是關於索引或替代UNION,將工作一樣。替代或解決方案UNION不要有數據手動
在進一步的例子中,我們假設title
text
和content
都具有fulltext
爲index
假設我們有三個報表
SELECT title as text FROM news ORDER BY score DESC
SELECT name as text FROM pages ORDER BY score DESC
SELECT content as text FROM comments ORDER BY score DESC
我們可以將它們組合起來(請注意,我們手動進行訂購)
SELECT title as text FROM news ORDER BY score DESC
UNION
SELECT name as text FROM pages ORDER BY score DESC
UNION
SELECT content as text FROM comments ORDER BY score DESC
現在我們已經text
,我們可以PRI NT但訂單將是1)消息2)3頁)評論
這是非常糟糕的,因爲我們希望這些按分數排序不同可能
因此,我們可以將所有這些THREE SELECTS
到ONE SELECT
和秩序他們
SELECT text FROM (
SELECT title as text FROM news ORDER BY score DESC
UNION
SELECT name as text FROM pages ORDER BY score DESC
UNION
SELECT content as text FROM comments ORDER BY score DESC
) as combination
現在我們可以通過score
再次ORDER
吧,這是非常糟糕的,因爲分數是根據每個表不是每個整選擇
所以,我們會繼續前進,我的問題更接近。
下一步是引進MATCH() and AGAINST()
和我們寫
SELECT text, MATCH(text) AGAINST ('anything') as total_score FROM (
SELECT title as text FROM news ORDER BY score DESC
UNION
SELECT name as text FROM pages ORDER BY score DESC
UNION
SELECT content as text FROM comments ORDER BY score DESC
) as combination ORDER BY total_score DESC
我們完成了!如果不是MATCH(text
)似乎不會被索引爲全文,那麼一切都應該完美。出現
錯誤:無法找到FULLTEXT指數相匹配的列列表
現在consufion來了,有可能是一無所有,但不知何故讓text
一個FULLTEXT
。不幸的是,作爲text
沒有這樣的列現有的數據庫,說你不能找到它在phpMyAdmin,使其FULLTEXT
這種方式。
我想延長name as text
進一步使其接近name as text type fulltext
或類似的東西,我找不到任何地方。
請幫我解決,我想聽聽任何東西,也許有另一種方式來解決這種情況?我不知道。我會非常感謝。
我想是這樣的:http://stackoverflow.com/questions/13904885/fulltext-search-scores-calculated-not-from- all-given-tables如果您有時間,請參閱它,否則感謝您的回覆。 – Davit