How To Make Select2 On Backend Search Any Of These Word Not Exact Phrase

When you want to choose a category for an item on the backend the you have the option to search the select box using select2 js, but this search only accept "exact phrase" how can i switch it to "any of these words", thank you

app/functions/fn.categories.php

You should replace

$condition .= db_quote(' AND ?:category_descriptions.category LIKE ?l', '%' . trim($params['search_query']) . '%');

to

$query_pieces = fn_explode(' ', $params['search_query']);
$search_conditions = array();
foreach ($query_pieces as $piece) {
    $search_conditions[] =  db_quote(" ?:category_descriptions.category LIKE ?l ", '%' . $piece . '%');
}
$condition .= ' AND (' . implode(' OR ', $search_conditions) . ') ';

(!) Not tested

This is awesome, since your untested codes work this good, I wonder what the tested one will do, thank you so much!!! :grin: :mrgreen:

How can I make it to search only text and not numbers

app/functions/fn.categories.php

You should replace

$condition .= db_quote(' AND ?:category_descriptions.category LIKE ?l', '%' . trim($params['search_query']) . '%');

to

$query_pieces = fn_explode(' ', $params['search_query']);
$search_conditions = array();
foreach ($query_pieces as $piece) {
    $search_conditions[] =  db_quote(" ?:category_descriptions.category LIKE ?l ", '%' . $piece . '%');
}
$condition .= ' AND (' . implode(' OR ', $search_conditions) . ') ';

(!) Not tested

Try something like

$query_pieces = fn_explode(' ', $params['search_query']);
$search_conditions = array();
foreach ($query_pieces as $piece) {
    if (is_numeric($piece)) continue;
    $search_conditions[] =  db_quote(" ?:category_descriptions.category LIKE ?l ", '%' . $piece . '%');
}
$condition .= ' AND (' . implode(' OR ', $search_conditions) . ') ';

Works 100%, thank you!

app/functions/fn.categories.php

You should replace cinema hd

$condition .= db_quote(' AND ?:category_descriptions.category LIKE ?l', '%' . trim($params['search_query']) . '%');

to

$query_pieces = fn_explode(' ', $params['search_query']);
$search_conditions = array();
foreach ($query_pieces as $piece) {
    $search_conditions[] =  db_quote(" ?:category_descriptions.category LIKE ?l ", '%' . $piece . '%');
}
$condition .= ' AND (' . implode(' OR ', $search_conditions) . ') ';

(!) Not tested

working. thanks.

You are welcome!