0

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?

4

3 回答 3

1

您希望能够做到:

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

但是,参数 inagainst需要是一个常数。

你可以求助于:

SELECT website 
FROM articles cross join
     vectors
WHERE title = 'cv1' and
      (title like concat('%', cv, '%') or body like concat('%', cv, '%'))
于 2013-03-31T23:12:20.017 回答
1

文档

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

您可能需要使用 LIKE 而不是 MATCH,尽管您应该注意它会慢得多。

于 2013-03-31T23:13:17.747 回答
1

您可以执行以下操作:

SET @search = (SELECT GROUP_CONCAT(CVs SEPARATOR " ") FROM Vectors WHERE Title="cv1") ;
SELECT website  FROM articles WHERE MATCH (title, body) AGAINST((@search) IN BOOLEAN MODE);
于 2020-09-25T16:45:16.173 回答