From 84ee8f10d68dcf4f266501dbe8a96940ba59b8a6 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 9 Sep 2021 11:31:46 +0200
Subject: [PATCH] bug searching in search function

---
 include/Product.php   | 9 +++++----
 include/functions.php | 9 +++------
 2 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/include/Product.php b/include/Product.php
index a3a98bc..d3dd24c 100644
--- a/include/Product.php
+++ b/include/Product.php
@@ -143,10 +143,11 @@ class Product extends Entity {
                 }
             } else if($field == 'tag') {
                 foreach($this->get_tags() as $tag) {
-                    $match = match($values, $tag, $matchAll);
-                    if($match) {
-                        $matches['tags'] = $tag;
-                        break;
+                    if(match($values, $tag)) {
+                        if(!array_key_exists('tags', $matches)) {
+                            $matches['tags'] = array();
+                        }
+                        $matches['tags'][] = $tag;
                     } else {
                         if($matchAll) {
                             return array();
diff --git a/include/functions.php b/include/functions.php
index 1f16f6f..099b4bb 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -253,19 +253,16 @@ function suggest_content($fieldname) {
     return $out;
 }
 
-function match($searchterms, $subject, $matchAll=false) {
-    $out = array();
+function match($searchterms, $subject) {
     if(!is_array($searchterms)) {
         $searchterms = array($searchterms);
     }
     foreach($searchterms as $term) {
         if(fnmatch('*'.$term.'*', $subject, FNM_CASEFOLD)) {
-            $out[] = $term;
-        } else if($matchAll) {
-            return array();
+            return true;
         }
     }
-    return $out;
+    return false;
 }
 
 function format_date($date) {