From: Christian Weiske Date: Fri, 5 Feb 2016 05:48:45 +0000 (+0100) Subject: add site GET parameter X-Git-Tag: v0.1.0~12 X-Git-Url: https://git.cweiske.de/phinde.git/commitdiff_plain/f1a5d014d126621afa80af017da751ccb5ab7f85 add site GET parameter --- diff --git a/.gitignore b/.gitignore index d041e45..bda5eeb 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /data/config.php +README.html diff --git a/README.rst b/README.rst index ba8a681..f1e0abb 100644 --- a/README.rst +++ b/README.rst @@ -1,8 +1,18 @@ Features ======== +- Crawler and indexer with the ability to run many in parallel +- Shows and highlights text that contains search words +- Boolean search queries: + + - ``foo bar`` searches for ``foo AND bar`` + - ``foo OR bar`` + - ``title:foo`` searches for ``foo`` only in the page title +- Facets for tag, domain, language and type - Site search - - Query: ``foo bar site:www.example.org/dir/`` + - Query: ``foo bar site:example.org/dir/`` + - or use the ``site`` GET parameter: + ``/?q=foo&site=example.org/dir`` Dependencies ============ diff --git a/data/templates/search.htm b/data/templates/search.htm index 4f3a252..d703784 100644 --- a/data/templates/search.htm +++ b/data/templates/search.htm @@ -14,6 +14,9 @@ diff --git a/data/templates/search/list.htm b/data/templates/search/list.htm index 46bf4ba..069dcf3 100644 --- a/data/templates/search/list.htm +++ b/data/templates/search/list.htm @@ -1,10 +1,16 @@ {% if hitcount == 0 %}

- Sorry, no results for "{{query}}". + No results + for "{{cleanQuery}}" + {% if site %} + on {{site}} +    |    + Show all results + {% endif %}

{% else %} -

- {{hitcount}} results +

+ {{hitcount}} {% if hitcount == 1 %}result{% else %}results{%endif%} for "{{cleanQuery}}" {% if site %} diff --git a/www/index.php b/www/index.php index 846d589..6f4ec8f 100644 --- a/www/index.php +++ b/www/index.php @@ -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,