From 40e94e05fb719a8436dbd73287d03eeae5352492 Mon Sep 17 00:00:00 2001 From: Stefan Bohacek Date: Fri, 18 Sep 2015 07:48:42 -0400 Subject: [PATCH] Search term1 AND term2 AND term3 etc by default as per #19. --- plugins/pico_search.php | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/plugins/pico_search.php b/plugins/pico_search.php index 782400dc..ac3b9ab8 100644 --- a/plugins/pico_search.php +++ b/plugins/pico_search.php @@ -30,21 +30,26 @@ public function before_render(&$twig_vars, &$twig) foreach($this->pages as $k => $page) { - $this->pages[$k]["score"] = 0; - $title = strtoupper($page["title"]); - $content = strtoupper($page["content"]); - $tags = strtoupper($page["tags"]); + $this->pages[$k]["score"] = 0; + $title = strtoupper($page["title"]); + $content = strtoupper($page["content"]); + $tags = strtoupper($page["tags"]); - if (strstr($title, $q)) $this->pages[$k]["score"]+= 10; - if (strstr($content, $q)) $this->pages[$k]["score"]+= 10; - if (strstr($tags, $q)) $this->pages[$k]["score"]+= 10; + if (strstr($title, $q)) $this->pages[$k]["score"]+= 10; + if (strstr($content, $q)) $this->pages[$k]["score"]+= 10; + if (strstr($tags, $q)) $this->pages[$k]["score"]+= 10; - foreach($qs as $query) - { - if (strstr($title, $query)) $this->pages[$k]["score"]+= 3; - if (strstr($content, $query)) $this->pages[$k]["score"]+= 3; - if (strstr($tags, $query)) $this->pages[$k]["score"]+= 3; - } + if (count(array_intersect($qs, explode(" ", $title))) == count($qs)){ + $this->pages[$k]["score"]+= 3; + } + + if (count(array_intersect($qs, explode(" ", $content))) == count($qs)){ + $this->pages[$k]["score"]+= 3; + } + + if (count(array_intersect($qs, explode(",", $tags))) == count($qs)){ + $this->pages[$k]["score"]+= 3; + } } $counts = array();