From 3c83676016bce1727f0046f4aad7865be8a71fd4 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Mon, 7 May 2012 20:36:13 +0200 Subject: use httprequest wrapper to automatically check for errors --- .../Database/Adapter/Elasticsearch/HTTPRequest.php | 25 ++++++++++++++++++++++ src/phorkie/Database/Setup/Elasticsearch.php | 22 +++++++++++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 src/phorkie/Database/Adapter/Elasticsearch/HTTPRequest.php (limited to 'src/phorkie/Database') diff --git a/src/phorkie/Database/Adapter/Elasticsearch/HTTPRequest.php b/src/phorkie/Database/Adapter/Elasticsearch/HTTPRequest.php new file mode 100644 index 0000000..2d74a4e --- /dev/null +++ b/src/phorkie/Database/Adapter/Elasticsearch/HTTPRequest.php @@ -0,0 +1,25 @@ +getStatus() / 100); + if ($mainCode != 2) { + $js = json_decode($res->getBody()); + if (isset($js->error)) { + $error = $js->error; + } else { + $error = $res->getBody(); + } + throw new Exception( + 'Error in elasticsearch communication: ' . $error + ); + } + return $res; + } +} + +?> diff --git a/src/phorkie/Database/Setup/Elasticsearch.php b/src/phorkie/Database/Setup/Elasticsearch.php index acf4bfc..b5e2005 100644 --- a/src/phorkie/Database/Setup/Elasticsearch.php +++ b/src/phorkie/Database/Setup/Elasticsearch.php @@ -10,9 +10,15 @@ class Database_Setup_Elasticsearch public function setup() { + $r = new Database_Adapter_Elasticsearch_HTTPRequest( + $this->searchInstance . 'repo/_mapping', + \HTTP_Request2::METHOD_DELETE + ); + $r->send(); + //create mapping //mapping for repositories - $r = new \HTTP_Request2( + $r = new Database_Adapter_Elasticsearch_HTTPRequest( $this->searchInstance . 'repo/_mapping', \HTTP_Request2::METHOD_PUT ); @@ -20,6 +26,10 @@ class Database_Setup_Elasticsearch json_encode( (object)array( 'repo' => (object)array( + '_timestamp' => (object)array( + 'enabled' => true, + 'path' => 'tstamp', + ), 'properties' => (object)array( 'id' => (object)array( 'type' => 'long' @@ -27,6 +37,14 @@ class Database_Setup_Elasticsearch 'description' => (object)array( 'type' => 'string', 'boost' => 2.0 + ), + 'crdate' => (object)array( + //creation date + 'type' => 'date', + ), + 'tstamp' => (object)array( + //modification date + 'type' => 'date', ) ) ) @@ -36,7 +54,7 @@ class Database_Setup_Elasticsearch $r->send(); //mapping for files - $r = new \HTTP_Request2( + $r = new Database_Adapter_Elasticsearch_HTTPRequest( $this->searchInstance . 'file/_mapping', \HTTP_Request2::METHOD_PUT ); -- cgit v1.2.3