X-Git-Url: https://git.cweiske.de/phinde.git/blobdiff_plain/9728ce82bfda5cada1fb19a921dbf6c34b76d8d6..cd02bac646f42a0cb402ff2dc8240aa01f1f0fb8:/www/index.php diff --git a/www/index.php b/www/index.php index 2598a43..6f4ec8f 100644 --- a/www/index.php +++ b/www/index.php @@ -4,7 +4,7 @@ namespace phinde; require 'www-header.php'; if (!isset($_GET['q'])) { - exit('no query'); + $_GET['q'] = ''; } $query = $_GET['q']; @@ -17,9 +17,23 @@ if (isset($_GET['page'])) { $page = (int)$_GET['page'] - 1; } $perPage = 10;//$GLOBALS['phinde']['perPage']; - +$site = null; +$siteParam = false; $baseLink = '?q=' . urlencode($query); +if (preg_match('#site:([^ ]*)#', $query, $matches)) { + $site = $matches[1]; + $cleanQuery = trim(str_replace('site:' . $site, '', $query)); + $site = Helper::noSchema($site); +} else if (isset($_GET['site']) && trim(isset($_GET['site'])) != '') { + $site = trim($_GET['site']); + $siteParam = true; + $cleanQuery = $query; + $baseLink .= '&site=' . urlencode($site); +} else { + $cleanQuery = $query; +} + $filters = array(); if (isset($_GET['filter'])) { $allowedFilter = array('domain', 'language', 'tags', 'term'); @@ -54,7 +68,6 @@ function buildLink($baseLink, $filters, $addFilterType, $addFilterValue) return $baseLink; } -$site = null; if (preg_match('#site:([^ ]*)#', $query, $matches)) { $site = $matches[1]; $cleanQuery = trim(str_replace('site:' . $site, '', $query)); @@ -77,7 +90,8 @@ $pager = new Html_Pager( foreach ($res->hits->hits as &$hit) { $doc = $hit->_source; - if ($doc->title == '') { + if (!isset($doc->title) || $doc->title == '') { + $doc->title = '(no title)'; $doc->htmlTitle = '(no title)'; } if (isset($hit->highlight->title[0])) { @@ -104,6 +118,12 @@ foreach ($res->aggregations as $key => &$aggregation) { } } +if ($site !== null) { + $urlNoSite = buildLink('?q=' . urlencode($cleanQuery), $filters, null, null); +} else { + $urlNoSite = null; +} + render( 'search', array( @@ -112,6 +132,7 @@ render( 'cleanQuery' => $cleanQuery, 'urlNoSite' => $urlNoSite, 'site' => $site, + 'siteParam' => $siteParam, 'hitcount' => $res->hits->total, 'hits' => $res->hits->hits, 'aggregations' => $res->aggregations,