aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--README.rst12
-rw-r--r--data/templates/search.htm3
-rw-r--r--data/templates/search/list.htm12
-rw-r--r--www/index.php27
5 files changed, 48 insertions, 7 deletions
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 @@
<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>
+ &#160;&#160;&#160;|&#160;&#160;&#160;
+ <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,