X-Git-Url: https://git.cweiske.de/phinde.git/blobdiff_plain/ae2d3a27072b157a9c3df2ba1e8101d6d3a70d4f..210a7ec82c46ed6e410f80be4b1149f5295b1306:/src/phinde/Elasticsearch.php diff --git a/src/phinde/Elasticsearch.php b/src/phinde/Elasticsearch.php index 5ad46e7..96a769b 100644 --- a/src/phinde/Elasticsearch.php +++ b/src/phinde/Elasticsearch.php @@ -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 @@ -87,6 +102,7 @@ class Elasticsearch array( 'query_string' => array( 'default_field' => '_all', + 'default_operator' => 'AND', 'query' => $query ) ), @@ -141,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(