4 class Indexer_Elasticsearch
6 public function __construct()
8 $this->searchInstance = $GLOBALS['phorkie']['cfg']['elasticsearch'];
12 public function addRepo(Repository $repo, $crdate = null)
14 if ($crdate == null) {
17 $this->updateRepo($repo, $crdate);
20 public function updateRepo(Repository $repo, $crdate = null)
23 $r = new Database_Adapter_Elasticsearch_HTTPRequest(
24 $this->searchInstance . 'repo/' . $repo->id,
25 \HTTP_Request2::METHOD_PUT
29 'description' => $repo->getDescription(),
30 'tstamp' => gmdate('c', time()),
32 if ($crdate !== null) {
33 $repoData['crdate'] = gmdate('c', $crdate);
35 $r->setBody(json_encode((object)$repoData));
39 //clean up before adding files; files might have been deleted
40 $this->deleteRepoFiles($repo);
42 foreach ($repo->getFiles() as $file) {
43 $r = new Database_Adapter_Elasticsearch_HTTPRequest(
44 $this->searchInstance . 'file/?parent=' . $repo->id,
45 \HTTP_Request2::METHOD_POST
50 'name' => $file->getFilename(),
51 'extension' => $file->getExt(),
52 'content' => $file->isText() ? $file->getContent() : '',
60 public function deleteAllRepos()
62 $r = new Database_Adapter_Elasticsearch_HTTPRequest(
63 $this->searchInstance . 'repo/_query',
64 \HTTP_Request2::METHOD_DELETE
69 'match_all' => (object)array()
74 $r = new Database_Adapter_Elasticsearch_HTTPRequest(
75 $this->searchInstance . 'file/_query',
76 \HTTP_Request2::METHOD_DELETE
81 'match_all' => (object)array()
88 public function deleteRepo(Repository $repo)
90 //delete repository from index
91 $r = new Database_Adapter_Elasticsearch_HTTPRequest(
92 $this->searchInstance . 'repo/' . $repo->id,
93 \HTTP_Request2::METHOD_DELETE
97 $this->deleteRepoFiles($repo);
100 protected function deleteRepoFiles(Repository $repo)
102 //delete files of that repository
103 $r = new Database_Adapter_Elasticsearch_HTTPRequest(
104 $this->searchInstance . 'file/_query',
105 \HTTP_Request2::METHOD_DELETE
110 'field' => (object)array(
111 '_parent' => $repo->id