I need to be able to search and to consider the different words as keywords instead of a string.

Actually, if I search "lamp blue", a result of "blue and white lamp" or "blue lamp" will not show up. I want to consider spaces as keywords separator. How can we do this simply considering my actual code ?

$pdo2_where = " WHERE (" .$db_type_1_associations['nom_bot'] ." LIKE ? || " .$db_type_1_associations['id'] ." LIKE ? || " .$db_type_1_associations['nom_fr'] ." LIKE ? || " .$db_type_1_associations['description'] ." LIKE ? || " .$db_type_1_associations['commentaire_public'] ." LIKE ?)" .$pdo2_add_where_photos ;
$pdo2_execute = array (
'%' .htmlspecialchars(urldecode(trim($_GET['recherche']))) .'%',
'%' .htmlspecialchars(urldecode(trim($_GET['recherche']))) .'%',
'%' .htmlspecialchars(urldecode(trim($_GET['recherche']))) .'%',
'%' .htmlspecialchars(urldecode(trim($_GET['recherche']))) .'%',
'%' .htmlspecialchars(urldecode(trim($_GET['recherche']))) .'%'
); 

*also it could be good to separate slashes, commas and other classic separators.

有帮助吗?

解决方案

This is a good time to be thinking about using a search engine. Or if possible, at least full text indexes.

You can do this with just SQL, but your query is going to get more complex. You will need to split your search string on spaces and add additional or clauses for each keyword and field combination.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top