bug searching in search function

This commit is contained in:
Viktor Pedersen 2021-09-09 11:31:46 +02:00
parent f1a731c859
commit 84ee8f10d6
2 changed files with 8 additions and 10 deletions

@ -143,10 +143,11 @@ class Product extends Entity {
} }
} else if($field == 'tag') { } else if($field == 'tag') {
foreach($this->get_tags() as $tag) { foreach($this->get_tags() as $tag) {
$match = match($values, $tag, $matchAll); if(match($values, $tag)) {
if($match) { if(!array_key_exists('tags', $matches)) {
$matches['tags'] = $tag; $matches['tags'] = array();
break; }
$matches['tags'][] = $tag;
} else { } else {
if($matchAll) { if($matchAll) {
return array(); return array();

@ -253,19 +253,16 @@ function suggest_content($fieldname) {
return $out; return $out;
} }
function match($searchterms, $subject, $matchAll=false) { function match($searchterms, $subject) {
$out = array();
if(!is_array($searchterms)) { if(!is_array($searchterms)) {
$searchterms = array($searchterms); $searchterms = array($searchterms);
} }
foreach($searchterms as $term) { foreach($searchterms as $term) {
if(fnmatch('*'.$term.'*', $subject, FNM_CASEFOLD)) { if(fnmatch('*'.$term.'*', $subject, FNM_CASEFOLD)) {
$out[] = $term; return true;
} else if($matchAll) {
return array();
} }
} }
return $out; return false;
} }
function format_date($date) { function format_date($date) {