Hi,
So basically I have an issue where the search field uses [keyword] OR [keyword] in the search instead of [keyword] AND [keyword] (if that makes any sense to you)
For example, when searching 'first floor' it displays anything that has 'first' or 'floor' in the post.
I did some research on this topic and found a solution that worked for the other person, they implemented a code into theme's 'functions.php' file, however it did nothing to the search, it is still the same.
The question being, is it possible to match all used keywords and display the block only if all the keywords are present?
Thank you in advance!
function cust_pattern_search_all_keywords_only($params) {
if (@$params['sPattern'] != '') {
$mSearch = Search::newInstance();
$query_elements = json_decode($mSearch->toJson(), true);
$pattern = $query_elements['sPattern'];
foreach (explode(' ', $pattern) as $word) {
//$query_elements['sPattern'] = str_replace($word, '+' . $word . '*', $query_elements['sPattern']); //search with wildcard egg => eggs
$query_elements['sPattern'] = str_replace($word, '+' . $word, $query_elements['sPattern']);
}
$mSearch->addLocale('%');
$mSearch->addGroupBy(DB_TABLE_PREFIX.'t_item.pk_i_id');
$mSearch->setJsonAlert($query_elements);
}
}
osc_add_hook('search_conditions', 'cust_pattern_search_all_keywords_only', 5);