X-Git-Url: https://git.cweiske.de/phinde.git/blobdiff_plain/7aba8a17bae437bfba2cb6c6496f750d014f3636..c916c3e93402408fa80aee3eac5a4ba451bef115:/src/phinde/Elasticsearch.php diff --git a/src/phinde/Elasticsearch.php b/src/phinde/Elasticsearch.php index c437036..2887beb 100644 --- a/src/phinde/Elasticsearch.php +++ b/src/phinde/Elasticsearch.php @@ -10,33 +10,15 @@ class Elasticsearch $this->baseUrl = $baseUrl; } - /** - * @link https://www.elastic.co/guide/en/elasticsearch/guide/current/_finding_exact_values.html - */ public function isKnown($url) { $r = new Elasticsearch_Request( - $this->baseUrl . 'document/_search/exists', - \HTTP_Request2::METHOD_GET + $this->baseUrl . 'document/' . rawurlencode($url), + \HTTP_Request2::METHOD_HEAD ); $r->allow404 = true; - $r->setBody( - json_encode( - array( - 'query' => array( - 'filtered' => array( - 'filter' => array( - 'term' => array( - 'url' => $url - ) - ) - ) - ) - ) - ) - ); - $res = json_decode($r->send()->getBody()); - return $res->exists; + $res = $r->send(); + return $res->getStatus() == 200; } public function get($url) @@ -70,13 +52,14 @@ class Elasticsearch 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 (preg_match_all('#nick:([^ ]*)#', $query, $matches)) { + foreach ($matches[1] as $authorName) { + $query = str_replace( + 'nick:' . $authorName, + 'author.name:' . $authorName, + $query + ); + } } $qMust = array();//query parts for the MUST section