我目前正试图为我的网站写一个多语言的搜索引号。
如果文本不存在于该语言中,我编写了一个函数来获取所请求语言的文本并回归到英语。
但是由于我收到错误,当在MATCH子句中调用函数并且我不想调用它3次时,我只是将函数代码编写为INNER JOIN,但是现在我丢失了我的FULLTEXT索引。
问题:
错误:
无法找到与列列表匹配的全文索引
TABLE"翻译":
Searchengine:(缩短)
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
提前致谢! - 民鼎
答案 0 :(得分:0)
以下是我解决问题的方法,以防有人遇到类似的问题:
采取另一种方法,而不是先加入,然后搜索我选择先搜索,然后加入:
#INSTEAD OF
COALESCE(tr2.text, tr1.text) AS description
#AND
MATCH(description) AGAINST(?) AS relevance_description
#USE
GREATEST(
MATCH(tr2.text) AGAINST(?),
MATCH(tr1.text) AGAINST(?)
) AS relevance_description