diff options
| author | Christian Weiske <cweiske@cweiske.de> | 2016-02-05 06:48:45 +0100 |
|---|---|---|
| committer | Christian Weiske <cweiske@cweiske.de> | 2016-02-05 06:48:45 +0100 |
| commit | f1a5d014d126621afa80af017da751ccb5ab7f85 (patch) | |
| tree | 1cc3cb5bb4baabaa56e4ec61f7952ca9a516d142 | |
| parent | 8dc6e4a159dce99b7b1e98ba71e0a9ad487a1dac (diff) | |
| download | phinde-f1a5d014d126621afa80af017da751ccb5ab7f85.tar.gz phinde-f1a5d014d126621afa80af017da751ccb5ab7f85.zip | |
add site GET parameter
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | README.rst | 12 | ||||
| -rw-r--r-- | data/templates/search.htm | 3 | ||||
| -rw-r--r-- | data/templates/search/list.htm | 12 | ||||
| -rw-r--r-- | www/index.php | 27 |
5 files changed, 48 insertions, 7 deletions
@@ -1 +1,2 @@ /data/config.php +README.html @@ -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 @@ <form class="navbar-form pull-left"> <input type="text" name="q" placeholder="Search" value="{{query}}" class="input-xxlarge"/> + {% if siteParam %} + <input type="hidden" name="site" value="{{site}}"/> + {% endif %} <button type="submit" class="btn">Find</button> </form> </div> 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 %} <p> - Sorry, no results for "<tt>{{query}}</tt>". + No results + for "<strong><tt>{{cleanQuery}}</tt></strong>" + {% if site %} + on <strong><tt>{{site}}</tt></strong> +    |    + <a href="{{urlNoSite}}">Show all results</a> + {% endif %} </p> {% else %} - <p class="resultinfo"> - {{hitcount}} results +<p class="resultinfo"> + {{hitcount}} {% if hitcount == 1 %}result{% else %}results{%endif%} for "<strong><tt>{{cleanQuery}}</tt></strong>" {% 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, |
