Do a MATCH AGAINST query but only the first word?

2

Good morning. I am working with a php script of a search engine that performs a query to a database mysql using MATCH AGAINST in a column with FULLTEXT INDEX the problem is for example, if in my database I have "Food Mexicana "and in the search engine I type" M "returns" Mexican Food "and what I want is for me to return only the results that have that letter in the first word, the query I'm doing it like this:

 $search_query = $_POST['searchQuery'] . '*';
 $sql = "SELECT cat FROM cat_table WHERE MATCH(cat) AGAINST(:search_query  IN BOOLEAN MODE)";
    
asked by El barto 02.10.2017 в 18:28
source

1 answer

0

What you can do is just take into account the first word when making MATCH , this can be done with SUBSTRING_INDEX :

$search_query = $_POST['searchQuery'] . '*';
$sql = "SELECT cat FROM cat_table WHERE MATCH(SUBSTRING_INDEX(cat, " ", 1)) AGAINST(:search_query  IN BOOLEAN MODE)";

More information at: link

    
answered by 02.10.2017 в 19:06