Big patch merging crawling+indexing into one command, new json document structure
[phinde.git] / www / index.php
index 54d5da80f4ba2afcdb455a4294854acd6b77d9a6..8bf81479b7cd651cc77230fd93d1ed3e8fe21158 100644 (file)
@@ -6,8 +6,8 @@ require 'www-header.php';
 if (!isset($_GET['q'])) {
     $_GET['q'] = '';
 }
+$query = trim($_GET['q']);
 
-$query = $_GET['q'];
 $page = 0;
 if (isset($_GET['page'])) {
     if (!is_numeric($_GET['page'])) {
@@ -115,8 +115,8 @@ foreach ($res->hits->hits as &$hit) {
 
     $doc->extra = new \stdClass();
     $doc->extra->cleanUrl = preg_replace('#^.*://#', '', $doc->url);
-    if (isset($doc->modate)) {
-        $doc->extra->day = substr($doc->modate, 0, 10);
+    if (isset($doc->status->modate)) {
+        $doc->extra->day = substr($doc->status->modate, 0, 10);
     }
 }
 
@@ -137,11 +137,20 @@ $urlSortRelevance = buildLink(
 );
 $urlSortDate = $urlSortRelevance . '&sort=date';
 
+if (isset($_GET['format']) && $_GET['format'] == 'opensearch') {
+    $template = 'opensearch';
+    $baseLink .= '&format=opensearch';
+    header('Content-type: application/atom+xml');
+} else {
+    $template = 'search';
+}
+
 render(
-    'search',
+    $template,
     array(
         'queryTime' => round($timeEnd - $timeBegin, 2) . 's',
         'query' => $query,
+        'fullUrl' => Helper::fullUrl($baseLink),
         'cleanQuery' => $cleanQuery,
         'urlNoSite' => $urlNoSite,
         'site' => $site,
@@ -154,6 +163,7 @@ render(
         'sort' => $sort,
         'urlSortRelevance' => $urlSortRelevance,
         'urlSortDate' => $urlSortDate,
+        'hitTemplate' => 'search/' . $GLOBALS['phinde']['hitTemplate'],
     )
 );
 ?>