X-Git-Url: https://git.cweiske.de/phinde.git/blobdiff_plain/87670eb07d1b0e82e0a8b4c1f9b9d20e3cafdb42..ea7a3af16218cfba55333e15d0eec856d595d59a:/www/index.php diff --git a/www/index.php b/www/index.php index 54d5da8..7c4904b 100644 --- a/www/index.php +++ b/www/index.php @@ -6,8 +6,8 @@ require 'www-header.php'; if (!isset($_GET['q'])) { $_GET['q'] = ''; } +$query = trim($_GET['q']); -$query = $_GET['q']; $page = 0; if (isset($_GET['page'])) { if (!is_numeric($_GET['page'])) { @@ -15,6 +15,12 @@ if (isset($_GET['page'])) { } //PEAR Pager begins at 1 $page = (int)$_GET['page'] - 1; + + if ($page >= 100) { + //Elasticsearch by default only allows 100 pages + // we do not want exceptions in our logs + throw new Exception_Input('List page is too large'); + } } $perPage = 10;//$GLOBALS['phinde']['perPage']; @@ -35,11 +41,16 @@ if (preg_match('#site:([^ ]*)#', $query, $matches)) { $cleanQuery = $query; } -if (isset($_GET['sort']) && $_GET['sort'] == 'date') { - $sort = 'date'; - $baseLink .= '&sort=date'; +if (isset($_GET['sort']) + && ($_GET['sort'] === 'date' || $_GET['sort'] === 'score') +) { + $sortMode = $_GET['sort']; } else { - $sort = ''; + $sortMode = $GLOBALS['phinde']['defaultSort']; +} +$sort = $sortMode; +if ($sortMode !== $GLOBALS['phinde']['defaultSort']) { + $baseLink .= '&sort=' . $sortMode; } $filters = array(); @@ -93,7 +104,7 @@ $timeEnd = microtime(true); $pager = new Html_Pager( $res->hits->total, $perPage, $page + 1, - $baseLink + buildLink($baseLink, $filters, null, null) ); foreach ($res->hits->hits as &$hit) { @@ -115,8 +126,8 @@ foreach ($res->hits->hits as &$hit) { $doc->extra = new \stdClass(); $doc->extra->cleanUrl = preg_replace('#^.*://#', '', $doc->url); - if (isset($doc->modate)) { - $doc->extra->day = substr($doc->modate, 0, 10); + if (isset($doc->status->modate)) { + $doc->extra->day = substr($doc->status->modate, 0, 10); } } @@ -132,16 +143,32 @@ if ($site !== null) { $urlNoSite = null; } -$urlSortRelevance = buildLink( - str_replace('&sort=date', '', $baseLink), $filters, null, null +$urlSortBase = buildLink( + preg_replace('#&sort=[^&]+#', '', $baseLink), $filters, null, null ); -$urlSortDate = $urlSortRelevance . '&sort=date'; +$urlSorts = []; +foreach (['date', 'score'] as $sortMode) { + if ($sortMode === $GLOBALS['phinde']['defaultSort']) { + $urlSorts[$sortMode] = $urlSortBase; + } else { + $urlSorts[$sortMode] = $urlSortBase . '&sort=' . $sortMode; + } +} + +if (isset($_GET['format']) && $_GET['format'] == 'opensearch') { + $template = 'opensearch'; + $baseLink .= '&format=opensearch'; + header('Content-type: application/atom+xml'); +} else { + $template = 'search'; +} render( - 'search', + $template, array( 'queryTime' => round($timeEnd - $timeBegin, 2) . 's', 'query' => $query, + 'fullUrl' => Helper::fullUrl($baseLink), 'cleanQuery' => $cleanQuery, 'urlNoSite' => $urlNoSite, 'site' => $site, @@ -152,8 +179,9 @@ render( 'activeFilters' => $activeFilters, 'pager' => $pager, 'sort' => $sort, - 'urlSortRelevance' => $urlSortRelevance, - 'urlSortDate' => $urlSortDate, + 'urlSorts' => $urlSorts, + 'hitTemplate' => 'search/' . $GLOBALS['phinde']['hitTemplate'], + 'sidebarinclude' => $GLOBALS['phinde']['sidebarinclude'], ) ); ?>