aboutsummaryrefslogtreecommitdiff
path: root/www/index.php
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2016-02-03 21:12:17 +0100
committerChristian Weiske <cweiske@cweiske.de>2016-02-03 21:12:17 +0100
commit88c741c09b664260f826ff947bfaab071ac70d05 (patch)
treeb2f7417aee5979d4bd994b929f71d518a3604aa0 /www/index.php
parentfab8cabe19ac99e3c8a95abcea3c0569b67045bb (diff)
downloadphinde-88c741c09b664260f826ff947bfaab071ac70d05.tar.gz
phinde-88c741c09b664260f826ff947bfaab071ac70d05.zip
add site search, highlighting
Diffstat (limited to 'www/index.php')
-rw-r--r--www/index.php27
1 files changed, 24 insertions, 3 deletions
diff --git a/www/index.php b/www/index.php
index 498cf93..12befbc 100644
--- a/www/index.php
+++ b/www/index.php
@@ -54,9 +54,18 @@ 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));
+ $site = Helper::noSchema($site);
+} else {
+ $cleanQuery = $query;
+}
+
$timeBegin = microtime(true);
$es = new Elasticsearch($GLOBALS['phinde']['elasticsearch']);
-$res = $es->search($query, $filters, $page, $perPage);
+$res = $es->search($cleanQuery, $filters, $site, $page, $perPage);
$timeEnd = microtime(true);
$pager = new Html_Pager(
@@ -67,8 +76,19 @@ $pager = new Html_Pager(
foreach ($res->hits->hits as &$hit) {
$doc = $hit->_source;
if ($doc->title == '') {
- $doc->title = '(no title)';
+ $doc->htmlTitle = '(no title)';
+ }
+ if (isset($hit->highlight->title[0])) {
+ $doc->htmlTitle = $hit->highlight->title[0];
+ } else {
+ $doc->htmlTitle = htmlspecialchars($doc->title);
}
+ if (isset($hit->highlight->text[0])) {
+ $doc->htmlText = $hit->highlight->text[0];
+ } else {
+ $doc->htmlText = null;
+ }
+
$doc->extra = new \stdClass();
$doc->extra->cleanUrl = preg_replace('#^.*://#', '', $doc->url);
if (isset($doc->modate)) {
@@ -81,13 +101,14 @@ foreach ($res->aggregations as $key => &$aggregation) {
$bucket->url = buildLink($baseLink, $filters, $key, $bucket->key);
}
}
-//var_dump($res->aggregations);
render(
'search',
array(
'queryTime' => round($timeEnd - $timeBegin, 2) . 'ms',
'query' => $query,
+ 'cleanQuery' => $cleanQuery,
+ 'site' => $site,
'hitcount' => $res->hits->total,
'hits' => $res->hits->hits,
'aggregations' => $res->aggregations,