delete previous files when updating
authorChristian Weiske <cweiske@cweiske.de>
Tue, 1 May 2012 20:32:53 +0000 (22:32 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Tue, 1 May 2012 20:32:53 +0000 (22:32 +0200)
src/phorkie/Indexer/Elasticsearch.php

index c2fcfcc..2921239 100644 (file)
@@ -32,6 +32,9 @@ class Indexer_Elasticsearch
         $r->send();
 
         //add files
         $r->send();
 
         //add files
+        //clean up before adding files; files might have been deleted
+        $this->deleteRepoFiles($repo);
+
         foreach ($repo->getFiles() as $file) {
             $r = new \HTTP_Request2(
                 $this->searchInstance . 'file/?parent=' . $repo->id,
         foreach ($repo->getFiles() as $file) {
             $r = new \HTTP_Request2(
                 $this->searchInstance . 'file/?parent=' . $repo->id,
@@ -59,6 +62,11 @@ class Indexer_Elasticsearch
         );
         $r->send();
 
         );
         $r->send();
 
+        $this->deleteRepoFiles($repo);
+    }
+
+    protected function deleteRepoFiles(Repository $repo)
+    {
         //delete files of that repository
         $r = new \HTTP_Request2(
             $this->searchInstance . 'file/_query',
         //delete files of that repository
         $r = new \HTTP_Request2(
             $this->searchInstance . 'file/_query',
@@ -67,7 +75,9 @@ class Indexer_Elasticsearch
         $r->setBody(
             json_encode(
                 (object)array(
         $r->setBody(
             json_encode(
                 (object)array(
-                    '_parent' => 'repo#' . $repo->id
+                    'field' => (object)array(
+                        '_parent' => $repo->id
+                    )
                 )
             )
         );
                 )
             )
         );