Skip to content

Commit

Permalink
Search term1 AND term2 AND term3 etc by default as per #19.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanbohacek committed Sep 18, 2015
1 parent ef9c101 commit 40e94e0
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions plugins/pico_search.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 40e94e0

Please sign in to comment.