aboutsummaryrefslogtreecommitdiff
path: root/www
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2016-02-05 06:48:45 +0100
committerChristian Weiske <cweiske@cweiske.de>2016-02-05 06:48:45 +0100
commitf1a5d014d126621afa80af017da751ccb5ab7f85 (patch)
tree1cc3cb5bb4baabaa56e4ec61f7952ca9a516d142 /www
parent8dc6e4a159dce99b7b1e98ba71e0a9ad487a1dac (diff)
downloadphinde-f1a5d014d126621afa80af017da751ccb5ab7f85.tar.gz
phinde-f1a5d014d126621afa80af017da751ccb5ab7f85.zip
add site GET parameter
Diffstat (limited to 'www')
-rw-r--r--www/index.php27
1 files changed, 24 insertions, 3 deletions
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,