I'm performing a search query with MATCH and AGAINST in Bolean Mode, and i have the keywords stored in an ARRAY to show they like a TAGS, when I IMPLODE the array values to construct the query statement it works fine, but i want to preserve the BOLEAN functionality search like "exact match" or other special characters.
Is it possible to insert quotes when the array value comes with a spaces?
INPUT: keyword1 keyword2 "exact match" keyword3
Covert to this array:
$keywords = array(
[0] = "keyword1",
[1] = "keyword2",
[2] = "exact match", <-- This came with quotes so is stored as a phrase
[3] = "keyword3"
);
Then i need to convert to SQL statement with implode:
$SQL = "SELEC field WHERE MATCH(keywords) AGAINST('";
$SQL .= implode(" ", $keywords);
$SQL .= "' IN BOOLEAN MODE)";
I Try to use ARRAY_FILTER() but it only discriminates one instead the other:
function words($var){
return preg_match('/\s/', $var);
}
$SQL = "SELEC field WHERE MATCH(keywords) AGAINST('";
$SQL .= implode(" ", array_filter($keywords, 'words'));
$SQL .= "' IN BOOLEAN MODE)";
//example above only outputs: exact match
My goal is to discriminates array value when the value comes with more than two words, the function adds quotes to the value
Expected Output:
$SQL = "SELECT field WHERE MATCH(keywords) AGAINST('keyword1 keyword2 "exact match" keyword3' IN BOOLEAN MODE)";
Thanks a lot for your help