delete elasticsearch index when indexing to clean up properly
authorChristian Weiske <cweiske@cweiske.de>
Tue, 8 May 2012 16:06:22 +0000 (18:06 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Tue, 8 May 2012 16:06:22 +0000 (18:06 +0200)
scripts/index.php
src/phorkie/Database/Adapter/Elasticsearch/Setup.php
src/phorkie/Database/Adapter/Null/Setup.php
src/phorkie/Database/ISetup.php
src/phorkie/SetupCheck.php

index 5afbee0..4b529d1 100644 (file)
@@ -28,13 +28,9 @@ if ($GLOBALS['phorkie']['cfg']['setupcheck']) {
 $db = new Database();
 $idx = $db->getIndexer();
 
-//cleanup
-echo "Deleting all index data\n";
-$idx->deleteAllRepos();
-
 //create mapping
-echo "Index setup\n";
-$db->getSetup()->setup();
+echo "Index reset\n";
+$db->getSetup()->reset();
 
 
 $rs = new Repositories();
index 066a21c..0df2874 100644 (file)
@@ -10,12 +10,29 @@ class Database_Adapter_Elasticsearch_Setup implements Database_ISetup
 
     public function setup()
     {
-        $r = new Database_Adapter_Elasticsearch_HTTPRequest(
-            $this->searchInstance . 'repo/_mapping',
+        $r = new \HTTP_Request2(
+            $this->searchInstance . '/_mapping', \HTTP_Request2::METHOD_GET
+        );
+        $res = $r->send();
+        if ($res->getStatus() == 404) {
+            $this->reset();
+        }
+    }
+
+    public function reset()
+    {
+        $r = new \HTTP_Request2(
+            $this->searchInstance,
             \HTTP_Request2::METHOD_DELETE
         );
         $r->send();
 
+        $r = new Database_Adapter_Elasticsearch_HTTPRequest(
+            $this->searchInstance,
+            \HTTP_Request2::METHOD_PUT
+        );
+        $r->send();
+
         //create mapping
         //mapping for repositories
         $r = new Database_Adapter_Elasticsearch_HTTPRequest(
index de23d0a..3850978 100644 (file)
@@ -4,6 +4,7 @@ namespace phorkie;
 class Database_Adapter_Null_Setup
 {
     public function setup() {}
+    public function reset() {}
 }
 
 ?>
index 1ac6b2f..bb7293e 100644 (file)
@@ -4,6 +4,7 @@ namespace phorkie;
 interface Database_ISetup
 {
     public function setup();
+    public function reset();
 }
 
 ?>
index 39c386e..8ead33f 100644 (file)
@@ -72,8 +72,8 @@ class SetupCheck
 
     public function checkDatabase()
     {
-        $dbs = new Database_Setup_Elasticsearch();
-        $dbs->setup();
+        $dbs = new Database();
+        $dbs->getSetup()->setup();
     }
 
     public function fail($msg)