Using a Subquery in the Against for a FULLTEXT search in Mysql

陌路散爱 提交于 2019-12-12 04:45:01

问题


In MySQL, I would like to do a FULLTEXT search on a table 'articles'. The text I want to search against would be located in another table, 'Vectors' under the column 'CVs'

I am trying:

SELECT website 
FROM articles
WHERE MATCH (title, body)
AGAINST(
    SELECT CVs
    FROM Vectors
    WHERE Title="cv1")

However, it keeps returning syntax error.

Is it possible to run a subquery in the AGAINST clause?


回答1:


You would like to be able to do:

SELECT website 
FROM articles cross join
     vectors
WHERE title = 'cv1' and MATCH (title, body) AGAINST(cv);

But, the argment in against needs to be a constant.

You can resort to:

SELECT website 
FROM articles cross join
     vectors
WHERE title = 'cv1' and
      (title like concat('%', cv, '%') or body like concat('%', cv, '%'))



回答2:


From the documentation

The search string must be a literal string, not a variable or a column name.

You probably need to use LIKE instead of MATCH, though you should note that it will be much slower.



来源:https://stackoverflow.com/questions/15735562/using-a-subquery-in-the-against-for-a-fulltext-search-in-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!