Skip to content

Commit

Permalink
feat: index manager
Browse files Browse the repository at this point in the history
  • Loading branch information
faustoq committed Jul 8, 2024
1 parent 7d35024 commit 5375260
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ $results = $client->search($query);
use OramaCloud\Manager\CloudManager;
use OramaCloud\Manager\IndexManager;

$manager = new CloudManager('<Your Orama Cloud Private API Key>');

$indexId = '<Index-ID>';
$index = new IndexManager($indexId, $manager);
$index = new IndexManager('<Your Index-ID>', '<Your Private API Key>');

// Empty data
$index->empty();
Expand Down
19 changes: 15 additions & 4 deletions src/Manager/IndexManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ class IndexManager
private $manager;
private $indexId = null;

public function __construct($indexID, CloudManager $manager)
public function __construct($indexID, $manager)
{
$this->manager = $manager;
$this->indexId = $indexID;

$this->manager->setIndexId($indexID);
$this->init($manager);
}

public function empty()
Expand Down Expand Up @@ -65,4 +63,17 @@ private function callIndexWebhook($endpoint, $payload = null)

return $this->manager->callIndexWebhook($endpoint, $payload);
}

private function init($manager)
{
if ($manager instanceof CloudManager) {
$this->manager = $manager;
} else if ($manager instanceof string) {
$this->manager = new CloudManager($manager);
} else {
throw new \Exception('Invalid manager parameter. It should be an instance of CloudManager or an API key string.');
}

$this->manager->setIndexId($this->indexId);
}
}

0 comments on commit 5375260

Please sign in to comment.