Skip to content
Snippets Groups Projects
Unverified Commit 1b48999c authored by Michael Große's avatar Michael Große
Browse files

refactor(search): move filtering by time into _ft_page*

This is the more appropriate place for that functionality, because now
it happens inside the default function for the respective pagesearch and
pagelookup events and can be properly handled by plugins.
parent 940f24fc
No related branches found
No related tags found
No related merge requests found
......@@ -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
*
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment