Support "nick:cweiske" search syntax as alias for "author.name"
[phinde.git] / src / phinde / Elasticsearch.php
index 316f3da..96a769b 100644 (file)
@@ -68,8 +68,23 @@ class Elasticsearch
         $r->send();
     }
 
-    public function search($query, $filters, $site, $page, $perPage)
+    public function search($query, $filters, $site, $page, $perPage, $sort)
     {
+        if (preg_match('#nick:([^ ]*)#', $query, $matches)) {
+            $authorName = $matches[1];
+            $query = str_replace(
+                'nick:' . $authorName,
+                'author.name:' . $authorName,
+                $query
+            );
+        }
+
+        if ($sort == 'date') {
+            $sortCfg = array('modate' => array('order' => 'desc'));
+        } else {
+            $sortCfg = array();
+        }
+
         $r = new Elasticsearch_Request(
             $this->baseUrl . 'document/_search',
             \HTTP_Request2::METHOD_GET
@@ -142,9 +157,7 @@ class Elasticsearch
             ),
             'from' => $page * $perPage,
             'size' => $perPage,
-            'sort' => array(
-                //array('modate' => array('order' => 'desc'))
-            )
+            'sort' => $sortCfg,
         );
         foreach ($filters as $type => $value) {
             $doc['query']['bool']['must'][] = array(