Skip to content

Commit

Permalink
feat: Rename getCompositeIdentifier to getIdempotentIdentifier and pr…
Browse files Browse the repository at this point in the history
…ovided a fallback.

BREAKING CHANGE: All Solr documents MUST have a idempotent ID field to ease up Solr indexing (no more need to delete previous index entry before indexing an entity).
  • Loading branch information
ambroisemaupate committed Mar 13, 2023
1 parent ed05a24 commit e8c895a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
14 changes: 12 additions & 2 deletions lib/RoadizCoreBundle/src/SearchEngine/AbstractSolarium.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public function cleanAndCommit(): void
public function index(): bool
{
if ($this->document instanceof Document) {
$this->document->setKey('id', $this->getCompositeIdentifier());
$this->document->setKey('id', $this->getIdempotentIdentifier());

try {
foreach ($this->getFieldsAssoc() as $key => $value) {
Expand Down Expand Up @@ -310,5 +310,15 @@ public function cleanTextContent(?string $content, bool $stripMarkdown = true):
return $content;
}

abstract protected function getCompositeIdentifier(): string;
/**
* You MUST override this method to provide an idempotent identifier.
* This identifier MUST be the same for the same entity.
*
* @return string
*/
protected function getIdempotentIdentifier(): string
{
// This is a fallback for backward compatibility.
return uniqid('', true);
}
}
2 changes: 1 addition & 1 deletion lib/RoadizCoreBundle/src/SearchEngine/SolariumDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public function index(): bool
return true;
}

protected function getCompositeIdentifier(): string
protected function getIdempotentIdentifier(): string
{
throw new \InvalidArgumentException('SolariumDocument should not provide any ID');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function clean(Query $update): bool
return true;
}

protected function getCompositeIdentifier(): string
protected function getIdempotentIdentifier(): string
{
$namespace = explode('\\', get_class($this->documentTranslation));
// get last 3 parts of namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function clean(Query $update): bool
return true;
}

protected function getCompositeIdentifier(): string
protected function getIdempotentIdentifier(): string
{
$namespace = explode('\\', get_class($this->nodeSource));
// get last 3 parts of namespace
Expand Down

0 comments on commit e8c895a

Please sign in to comment.