0
我目前正在嘗試爲我的網站寫一點多語言搜索引擎。如何在不丟失FULLTEXT-Index的情況下連接表格?
我寫了一個函數來獲取所需語言的文本,並回退到英語,如果該文本不存在該語言。
但是,由於我得到一個錯誤,當調用MATCH子句中的函數時,我不想再調用它3次,我只寫了函數代碼作爲INNER JOIN,,但現在我失去了我的FULLTEXT索引。
問題:
- 如何維護我的FULLTEXT指數?
- 有沒有比加入第二個表更好的方法?
- 還有其他錯誤嗎?
錯誤:
Can't find fulltext index matching the column list
表 「翻譯」:
- TYPE ------ NAME ---- INDEX
- INT- --------「ID」------- 唯一(主)
- INT --------- 「tr_num」 -
- TEXT 「-----」 文本 「----- FULLTEXT
- CHAR(2) - 」 郎「 - ----
的搜索引擎:(縮短)
SELECT
c.ID,
c.name,
tr.description,
MATCH(c.name) AGAINST(?) AS relevance_title,
MATCH(tr.description) AGAINST(?) AS relevance_description,
FROM
companies c
#Joining transations (function code)
INNER JOIN (
SELECT
tr1.tr_num,
#Select translation if available
COALESCE(tr2.text, tr1.text) AS description
FROM
translations tr1
LEFT JOIN
translations tr2
ON
tr1.tr_num = tr2.tr_num
AND
tr2.lang = '$lang' #PHP - preferred langauge
WHERE
tr1.lang = 'en' #default language (english)
) tr
ON
tr.tr_num = c.description_tr_num
WHERE
MATCH(c.name) AGAINST(?)
OR MATCH(tr.description) AGAINST(?)
ORDER BY
((relevance_title * "/*PHP*/.$config['relevance_title'].") + (relevance_description * "/*PHP*/.$config['relevance_description'].")) DESC
功能:(不重要 - 只是櫃面我可以在我的搜索使用它)
BEGIN
DECLARE output TEXT;
SELECT
COALESCE(tr2.text, tr1.text)
INTO
output
FROM
translations tr1
LEFT JOIN
translations tr2
ON
tr1.tr_num = tr2.tr_num
AND
tr2.lang = input_lang
WHERE
tr1.tr_num = input_tr_num
AND
tr1.lang = 'en';
RETURN output;
END
在此先感謝! - 自掃門前雪