Skip to content

Commit

Permalink
Remove ES index prefix from MultiIndexWrapper
Browse files Browse the repository at this point in the history
Remove the index prefix from arElasticSearchMultiIndexWrapper and use
AtoM class names internally instead of using prefix to refer to them.
  • Loading branch information
anvit committed Nov 22, 2024
1 parent 9adb350 commit fc6d069
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,25 @@
*/

/**
* arElasticSearchMultiIndexWrapper facilitates handling ElasticSearch indices so that
* all indices for an AtoM installation can share a common prefix without having to
* explicitly specify it in common indexing and search functions.
* arElasticSearchMultiIndexWrapper facilitates handling ElasticSearch indices
* and has methods that match signatures of pre ES 6.x methods that used a
* single index with multiple types instead of multiple index with a single
* type or no type.
*/
class arElasticSearchMultiIndexWrapper
{
protected $indices;

protected $indexPrefix;

public function __construct($prefix)
public function __construct()
{
$this->indices = [];

$this->indexPrefix = $prefix;
}

public function addIndex($name, Elastica\Index $index)
{
$name = $this->getIndexName($name);
$this->indices[$name] = $index;
}

// Converts camelized Qubit class names to lower case index name used for ElasticSearch
public function getIndexName($name)
{
return $this->indexPrefix.'_'.strtolower($name);
}

public function delete()
{
foreach ($this->indices as $index) {
Expand All @@ -56,13 +46,11 @@ public function delete()

public function addDocuments($name, $documents)
{
$name = $this->getIndexName($name);
$this->indices[$name]->addDocuments($documents);
}

public function deleteDocuments($name, $documents)
{
$name = $this->getIndexName($name);
$this->indices[$name]->deleteDocuments($documents);
}

Expand All @@ -77,8 +65,6 @@ public function refresh()
// that matches the qualified index name
public function getIndex($name)
{
$name = $this->getIndexName($name);

return $this->indices[$name];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function __construct(array $options = [])
// Verify the version running in the server
$this->checkVersion();

$this->index = new arElasticSearchMultiIndexWrapper($this->config['index']['name']);
$this->index = new arElasticSearchMultiIndexWrapper();

// Load batch mode configuration
$this->batchMode = true === $this->config['batch_mode'];
Expand Down Expand Up @@ -547,8 +547,9 @@ protected function initialize()
// Iterate over types (actor, informationobject, ...)
foreach ($this->mappings as $indexName => $indexProperties) {
$indexName = 'Qubit'.sfInflector::camelize($indexName);
$prefixedIndexName = $this->config['index']['name'].'_'.strtolower($indexName);
$this->index->addIndex($indexName,
$this->client->getIndex($this->index->getIndexName($indexName))
$this->client->getIndex($prefixedIndexName)
);
}

Expand Down Expand Up @@ -592,7 +593,7 @@ protected function initialize()
foreach ($this->mappings as $indexName => $indexProperties) {
$indexName = 'Qubit'.sfInflector::camelize($indexName);

if ($indexType != $this->index->getIndexName($indexName)) {
if ($indexType != $indexName) {
continue;
}

Expand Down

0 comments on commit fc6d069

Please sign in to comment.