I have keywords column in my table and there are comma (,) separated values. example: hello, world
I have search engine with same codes:
$search = $_GET ['search'];
$query = $db->prepare("SELECT COUNT(*) as num FROM table WHERE keywords LIKE ?");
$query->bindValue(1, "%$search%", PDO::PARAM_STR);
$query->execute();
$sql = $db->prepare("SELECT * FROM table WHERE keywords LIKE ? LIMIT $start , $limit");
$sql->bindValue(1, "%$search%", PDO::PARAM_STR);
$sql->execute();
When I type only 'hello' or only 'world' in my search bar, there is result, but if I type both words together, like 'Hello world' there is no result.
EDIT:
I edited my codes for FULL TEXT SEARCH
$query = $db->prepare("SELECT COUNT(*) as num FROM table WHERE MATCH (id,keywords) AGAINST ('$search*' IN BOOLEAN MODE)");
$query->execute();
and
$sql = $db->prepare("SELECT * FROM table WHERE MATCH (id,keywords) AGAINST ('$search*' IN BOOLEAN MODE) LIMIT $start , $limit");
$sql->execute();
It works better, but now I get some irrelevant results. Is there any way to filter results and order they relevance?
Thanks
Best Answer
If you must keep
keywords
as a CSV, you can useFIND_IN_SET()
.