aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2012-05-02 18:18:17 +0200
committerChristian Weiske <cweiske@cweiske.de>2012-05-02 18:18:17 +0200
commit3bc2092b7732a33db738e12afde32645e49d5c47 (patch)
tree340f0a6eb7a02997749c99ff29121c265edbdfeb
parent6d445737a4b814bedb2787ac4504352df38b48d2 (diff)
downloadphorkie-3bc2092b7732a33db738e12afde32645e49d5c47.tar.gz
phorkie-3bc2092b7732a33db738e12afde32645e49d5c47.zip
automatic mapping setup for elasticsearch through setupcheck
-rw-r--r--src/phorkie/Database/Setup/Elasticsearch.php73
-rw-r--r--src/phorkie/SetupCheck.php7
2 files changed, 80 insertions, 0 deletions
diff --git a/src/phorkie/Database/Setup/Elasticsearch.php b/src/phorkie/Database/Setup/Elasticsearch.php
new file mode 100644
index 0000000..acf4bfc
--- /dev/null
+++ b/src/phorkie/Database/Setup/Elasticsearch.php
@@ -0,0 +1,73 @@
+<?php
+namespace phorkie;
+
+class Database_Setup_Elasticsearch
+{
+ public function __construct()
+ {
+ $this->searchInstance = $GLOBALS['phorkie']['cfg']['elasticsearch'];
+ }
+
+ public function setup()
+ {
+ //create mapping
+ //mapping for repositories
+ $r = new \HTTP_Request2(
+ $this->searchInstance . 'repo/_mapping',
+ \HTTP_Request2::METHOD_PUT
+ );
+ $r->setBody(
+ json_encode(
+ (object)array(
+ 'repo' => (object)array(
+ 'properties' => (object)array(
+ 'id' => (object)array(
+ 'type' => 'long'
+ ),
+ 'description' => (object)array(
+ 'type' => 'string',
+ 'boost' => 2.0
+ )
+ )
+ )
+ )
+ )
+ );
+ $r->send();
+
+ //mapping for files
+ $r = new \HTTP_Request2(
+ $this->searchInstance . 'file/_mapping',
+ \HTTP_Request2::METHOD_PUT
+ );
+ $r->setBody(
+ json_encode(
+ (object)array(
+ 'file' => (object)array(
+ '_parent' => (object)array(
+ 'type' => 'repo'
+ ),
+ 'properties' => (object)array(
+ 'name' => (object)array(
+ 'type' => 'string',
+ 'boost' => 1.5
+ ),
+ 'extension' => (object)array(
+ 'type' => 'string',
+ 'boost' => 1.0
+ ),
+ 'content' => (object)array(
+ 'type' => 'string',
+ 'boost' => 0.8
+ )
+ )
+ )
+ )
+ )
+ );
+ $r->send();
+ }
+
+}
+
+?>
diff --git a/src/phorkie/SetupCheck.php b/src/phorkie/SetupCheck.php
index ba52d42..0bb632f 100644
--- a/src/phorkie/SetupCheck.php
+++ b/src/phorkie/SetupCheck.php
@@ -28,6 +28,7 @@ class SetupCheck
$sc->checkDeps();
$sc->checkDirs();
$sc->checkGit();
+ $sc->checkDatabase();
}
public function checkDeps()
@@ -67,6 +68,12 @@ class SetupCheck
}
}
+ public function checkDatabase()
+ {
+ $dbs = new Database_Setup_Elasticsearch();
+ $dbs->setup();
+ }
+
public function fail($msg)
{
throw new Exception($msg);