diff --git a/inc/Ui/Search.php b/inc/Ui/Search.php index a746a6fd66adbed66afdb8b14a77c48c05de0a59..72b944a26c05797bb07dcf8bfe674228ff243072 100644 --- a/inc/Ui/Search.php +++ b/inc/Ui/Search.php @@ -31,45 +31,11 @@ class Search extends Ui */ public function execute() { - $this->pageLookupResults = $this->filterResultsByTime( - ft_pageLookup($this->query, true, useHeading('navigation')) - ); - $this->fullTextResults = $this->filterResultsByTime( - ft_pageSearch($this->query, $highlight) - ); + $this->pageLookupResults = ft_pageLookup($this->query, true, useHeading('navigation')); + $this->fullTextResults = ft_pageSearch($this->query, $highlight); $this->highlight = $highlight; } - /** - * @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'); - $after = is_int($after) ? $after : strtotime($after); - - $before = $INPUT->str('before'); - $before = is_int($before) ? $before : strtotime($before); - - // todo: should we filter $this->pageLookupResults as well? - foreach ($results as $id => $value) { - $mTime = filemtime(wikiFN($id)); - if ($after && $after > $mTime) { - unset($results[$id]); - continue; - } - if ($before && $before < $mTime) { - unset($results[$id]); - } - } - } - - return $results; - } - /** * display the search result * diff --git a/inc/fulltext.php b/inc/fulltext.php index 9034d229beb3b3b8c17682724330fd94c0c22295..987010c939c7540ec6b50d2e247041f528d8e509 100644 --- a/inc/fulltext.php +++ b/inc/fulltext.php @@ -134,6 +134,7 @@ function _ft_pageSearch(&$data) { } } + $docs = _ft_filterResultsByTime($docs); // sort docs by count arsort($docs); @@ -281,10 +282,42 @@ function _ft_pageLookup(&$data){ } } + $pages = _ft_filterResultsByTime($pages); + uksort($pages,'ft_pagesorter'); return $pages; } + +/** + * @param array $results search results in the form pageid => value + * + * @return array + */ +function _ft_filterResultsByTime(array $results) { + global $INPUT; + if ($INPUT->has('after') || $INPUT->has('before')) { + $after = $INPUT->str('after'); + $after = is_int($after) ? $after : strtotime($after); + + $before = $INPUT->str('before'); + $before = is_int($before) ? $before : strtotime($before); + + foreach ($results as $id => $value) { + $mTime = filemtime(wikiFN($id)); + if ($after && $after > $mTime) { + unset($results[$id]); + continue; + } + if ($before && $before < $mTime) { + unset($results[$id]); + } + } + } + + return $results; +} + /** * Tiny helper function for comparing the searched title with the title * from the search index. This function is a wrapper around stripos with