Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(search): also filter pagename results by time
  • Loading branch information
micgro42 committed Mar 26, 2018
1 parent d22b78c commit b3cfe85
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions inc/Ui/Search.php
Expand Up @@ -31,11 +31,21 @@ public function __construct()
*/
public function execute()
{
$this->pageLookupResults = ft_pageLookup($this->query, true, useHeading('navigation'));
$this->fullTextResults = ft_pageSearch($this->query, $highlight);
$this->pageLookupResults = $this->filterResultsByTime(
ft_pageLookup($this->query, true, useHeading('navigation'))
);
$this->fullTextResults = $this->filterResultsByTime(
ft_pageSearch($this->query, $highlight)
);
$this->highlight = $highlight;
}

// fixme: find better place for this
/**
* @param array $results search results in the form pageid => value
*
* @return array
*/
protected function filterResultsByTime(array $results) {
global $INPUT;
if ($INPUT->has('after') || $INPUT->has('before')) {
$after = $INPUT->str('after');
Expand All @@ -45,17 +55,19 @@ public function execute()
$before = is_int($before) ? $before : strtotime($before);

// todo: should we filter $this->pageLookupResults as well?
foreach ($this->fullTextResults as $id => $cnt) {
foreach ($results as $id => $value) {
$mTime = filemtime(wikiFN($id));
if ($after && $after > $mTime) {
unset($this->fullTextResults[$id]);
unset($results[$id]);
continue;
}
if ($before && $before < $mTime) {
unset($this->fullTextResults[$id]);
unset($results[$id]);
}
}
}

return $results;
}

/**
Expand Down

0 comments on commit b3cfe85

Please sign in to comment.