6.4 (current)
Search…
⌃K
Links

Completion

The Advanced Search does not use the default Elasticsearch Completion, because it does only support a fixed order and the storage size is high. As an alternative, the Advanced Search uses aggregations to find the most important words combinations for your search input.
The Full Text Boosted field is used to generate a list of completions. Each word is a separate completion suggestion.

Extension for compound completions

The default Advanced Search does not support compound completions from multiple words.
To support compound completions, it's necessary to decorate the appropriate Elasticsearch Definition. And add the Tag swag_ses.completion_definition to the service, like to Advanced Search default services. Make sure, that the new created decorator runs after the Advanced Search decorator, otherwise it will override your values.
MyProductDefinitionDecorator.php
<?php declare(strict_types=1);
namespace Swag\Example\Completion;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\Entity;
use Shopware\Core\Framework\DataAbstractionLayer\EntityCollection;
use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Elasticsearch\Framework\AbstractElasticsearchDefinition;
use Shopware\Elasticsearch\Framework\FullText;
class MyProductDefinitionDecorator extends AbstractElasticsearchDefinition
{
private AbstractElasticsearchDefinition $decorated;
public function __construct(
AbstractElasticsearchDefinition $decorated
) {
$this->decorated = $decorated;
}
public function getMapping(Context $context): array
{
return $this->decorated->getMapping($context);
}
public function extendCriteria(Criteria $criteria): void
{
$this->decorated->extendCriteria($criteria);
}
public function buildFullText(Entity $entity): FullText
{
return $this->decorated->buildFullText($entity);
}
public function getEntityDefinition(): EntityDefinition
{
return $this->decorated->getEntityDefinition();
}
public function extendEntities(EntityCollection $collection): EntityCollection
{
$collection = $this->decorated->extendEntities($collection);
foreach ($collection->getIterator() as $entity) {
// Here you can add your custom completions
$completionTerms = ['blue shoes', 'green socks'];
CompletionExtension::addCompletionExtension($entity, $completionTerms);
}
return $collection;
}
}
Last modified 2mo ago