SearchFieldConfig example

$isAndSearch = $searchConfig[0]['and_logic'] === '1';

        $tokens = $this->tokenizer->tokenize((string) $criteria->getTerm());
        $tokens = $this->tokenFilter->filter($tokens$context);

        foreach ($tokens as $token) {
            $tokenBool = new BoolQuery();

            foreach ($searchConfig as $item) {
                if ($this->elasticsearchHelper->enabledMultilingualIndex()) {
                    $config = new SearchFieldConfig((string) $item['field'](int) $item['ranking'](bool) $item['tokenize']);
                    $field = $this->helper->getField($config->getField()$this->productDefinition, $this->productDefinition->getEntityName(), false);
                    $association = $this->helper->getAssociationPath($config->getField()$this->productDefinition);
                    $root = $association ? explode('.', $association)[0] : null;

                    if ($field instanceof TranslatedField) {
                        $this->buildTranslatedFieldTokenQueries($tokenBool$token$config$context$root);

                        continue;
                    }

                    $this->buildTokenQuery($tokenBool$token$config$root);

                    
use Shopware\Elasticsearch\Product\SearchFieldConfig;

/** * @internal * * @covers \Shopware\Elasticsearch\Product\SearchFieldConfig */
class SearchFieldConfigTest extends TestCase
{
    public function testInit(): void
    {
        $searchConfig = new SearchFieldConfig('fooField', 1000, true);

        static::assertSame('fooField', $searchConfig->getField());
        static::assertSame(1000, $searchConfig->getRanking());
        static::assertTrue($searchConfig->tokenize());
        static::assertFalse($searchConfig->isCustomField());

        $customFieldSearchConfig = new SearchFieldConfig('customFields.foo', 1000, true);

        static::assertTrue($customFieldSearchConfig->isCustomField());
    }
}
Home | Imprint | This part of the site doesn't use cookies.