getRanking example

$productId = Uuid::fromHexToBytes($product->getId());

            foreach ($analyzed as $keyword) {
                $keywords[] = [
                    'id' => Uuid::randomBytes(),
                    'version_id' => $versionId,
                    'product_version_id' => $versionId,
                    'language_id' => $languageId,
                    'product_id' => $productId,
                    'keyword' => $keyword->getKeyword(),
                    'ranking' => $keyword->getRanking(),
                    'created_at' => $now,
                ];
                $key = $keyword->getKeyword() . $languageId;
                $dictionary[$key] = [
                    'id' => Uuid::randomBytes(),
                    'language_id' => $languageId,
                    'keyword' => $keyword->getKeyword(),
                ];
            }
        }

        

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());
    }
}
++$counter;

        $fields = $this->getQueryFields($definition$context);

        $queries = [];
        foreach ($fields as $field) {
            /** @var SearchRanking|null $flag */
            $flag = $field->getFlag(SearchRanking::class);

            $ranking = $multiplier;
            if ($flag) {
                $ranking = $flag->getRanking() * $multiplier;
            }

            if ($field instanceof DateTimeField) {
                if (!$this->validateDateFormat(Defaults::STORAGE_DATE_FORMAT, $term->getOriginal()->getTerm())) {
                    continue;
                }
            }

            $select = $root . '.' . $field->getPropertyName();

            if ($field instanceof ManyToManyAssociationField) {
                
'ean',
                'tag2',
                'tag1',
                'red',
                'tet',
                'customfield',
                123456,
                123456789,
            ];

            foreach ($analyzer->getElements() as $keyword) {
                static::assertEquals($ranking$keyword->getRanking());
            }
        }

        if ($searchable && !$tokenize) {
            $expected = [
                'Search Keyword Update',
                'Test category',
                'manufacturer customfield',
                'category customfield',
                'f023204e895b4cec8492ec14194e10d2',
                'metaDescription test',
                


        throw ElasticsearchProductException::configNotFound();
    }

    private function buildTokenQuery(BoolQuery $tokenBool, string $token, SearchFieldConfig $config, ?string $root = null): void
    {
        $queries = [];

        $searchField = $config->isCustomField() ? $config->getField() : $config->getField() . '.search';

        $queries[] = new MatchQuery($searchField$token['boost' => 5 * $config->getRanking()]);
        $queries[] = new MatchPhrasePrefixQuery($searchField$token['boost' => $config->getRanking(), 'slop' => 5]);
        $queries[] = new WildcardQuery($searchField, '*' . $token . '*');

        if ($config->tokenize()) {
            $ngramField = $config->isCustomField() ? $config->getField() : $config->getField() . '.ngram';
            $queries[] = new MatchQuery($searchField$token['fuzziness' => 'auto', 'boost' => 3 * $config->getRanking()]);
            $queries[] = new MatchQuery($ngramField$token);
        }

        foreach ($queries as $query) {
            if ($root) {
                

        return AnalyzedKeyword::class;
    }

    private function getBest(AnalyzedKeyword $new, string $keyword): AnalyzedKeyword
    {
        $existing = $this->has($keyword) ? $this->get($keyword) : null;
        if ($existing === null) {
            return $new;
        }

        return $new->getRanking() > $existing->getRanking() ? $new : $existing;
    }
}
Home | Imprint | This part of the site doesn't use cookies.