Big patch merging crawling+indexing into one command, new json document structure
[phinde.git] / bin / setup.php
index 7dacedd08b63b2551e3b79a48375d69d39635c9a..27c5c460504cd33a09d834d0a0f62f1357de6cc9 100755 (executable)
@@ -1,11 +1,19 @@
 #!/usr/bin/env php
 <?php
 namespace phinde;
-//configure the elasticsearch index
-set_include_path(__DIR__ . '/../src/' . PATH_SEPARATOR . get_include_path());
-require_once __DIR__ . '/../data/config.php';
-require_once 'HTTP/Request2.php';
-require_once 'Elasticsearch/Request.php';
+/**
+ * Configure the elasticsearch index.
+ * Throws away all data.
+ */
+require_once __DIR__ . '/../src/init.php';
+
+$json = file_get_contents(__DIR__ . '/../data/elasticsearch-mapping.json');
+if (json_decode($json) === null) {
+    echo "Error: Schema JSON is broken\n";
+    chdir(__DIR__ . '/../');
+    passthru('json_pp -t null < data/elasticsearch-mapping.json');
+    exit(1);
+}
 
 //delete old index
 $r = new Elasticsearch_Request(
@@ -20,8 +28,6 @@ $r = new Elasticsearch_Request(
     $GLOBALS['phinde']['elasticsearch'],
     \HTTP_Request2::METHOD_PUT
 );
-$r->setBody(
-    file_get_contents(__DIR__ . '/../data/elasticsearch-mapping.json')
-);
+$r->setBody($json);
 $r->send();
 ?>