Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

MATCH AGAINST functions are not working with two columns

I need fulltext search in two columns. The columns have fulltext indexes, but the problem is that the query works only with one parameter inside the MATCH function. With two columns, the query returns an empty result.

<?php

$s = "search keyword";

$query = "
    SELECT source,title,description,link,pubdate FROM feeds
    USE INDEX(PRIMARY)
    WHERE (MATCH(title,description) AGAINST(? IN NATURAL LANGUAGE MODE) 
    LIMIT 40
";

$st = $cn->prepare($query);
$st->bind_param("s",$s);
$st->execute();
$result = $st->get_result();

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You need a compound FULLTEXT index on both columns, not a separate FULLTEXT index on each column.

ALTER TABLE `feeds` ADD FULLTEXT INDEX `i_title_description`(`title`, `description`);

Also your SELECT is missing quotes in AGAINST

SELECT * FROM feeds WHERE (MATCH (title, description) AGAINST ('? IN NATURAL LANGUAGE MODE'))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading