4 class Indexer_Elasticsearch
6 public function __construct()
8 $this->searchInstance = $GLOBALS['phorkie']['cfg']['elasticsearch'];
12 public function addRepo(Repository $repo)
14 $this->updateRepo($repo);
17 public function updateRepo(Repository $repo)
20 $r = new \HTTP_Request2(
21 $this->searchInstance . 'repo/' . $repo->id,
22 \HTTP_Request2::METHOD_PUT
28 'description' => $repo->getDescription(),
35 //clean up before adding files; files might have been deleted
36 $this->deleteRepoFiles($repo);
38 foreach ($repo->getFiles() as $file) {
39 $r = new \HTTP_Request2(
40 $this->searchInstance . 'file/?parent=' . $repo->id,
41 \HTTP_Request2::METHOD_POST
46 'name' => $file->getFilename(),
47 'extension' => $file->getExt(),
48 'content' => $file->isText() ? $file->getContent() : '',
56 public function deleteRepo(Repository $repo)
58 //delete repository from index
59 $r = new \HTTP_Request2(
60 $this->searchInstance . 'repo/' . $repo->id,
61 \HTTP_Request2::METHOD_DELETE
65 $this->deleteRepoFiles($repo);
68 protected function deleteRepoFiles(Repository $repo)
70 //delete files of that repository
71 $r = new \HTTP_Request2(
72 $this->searchInstance . 'file/_query',
73 \HTTP_Request2::METHOD_DELETE
78 'field' => (object)array(
79 '_parent' => $repo->id