Skip to content

Commit

Permalink
Added CriterionVisitor for ContentNameCriterion
Browse files Browse the repository at this point in the history
  • Loading branch information
ciastektk committed Dec 19, 2023
1 parent 9e8b789 commit 5f792d9
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/lib/Query/Content/CriterionVisitor/ContentName.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Solr\Query\Content\CriterionVisitor;

use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion;
use Ibexa\Contracts\Solr\Query\CriterionVisitor;
use QueryTranslator\Languages\Galach\Generators\ExtendedDisMax;
use QueryTranslator\Languages\Galach\Parser;
use QueryTranslator\Languages\Galach\Tokenizer;

final class ContentName extends CriterionVisitor
{
private Tokenizer $tokenizer;

private Parser $parser;

private ExtendedDisMax $generator;

public function __construct(
Tokenizer $tokenizer,
Parser $parser,
ExtendedDisMax $generator
) {
$this->tokenizer = $tokenizer;
$this->parser = $parser;
$this->generator = $generator;
}

public function canVisit(Criterion $criterion): bool
{
return $criterion instanceof Criterion\ContentNameCriterion
&& $criterion->operator === Criterion\Operator::LIKE;
}

public function visit(Criterion $criterion, CriterionVisitor $subVisitor = null): string
{
/** @var string $value */
$value = $criterion->value;
$tokenSequence = $this->tokenizer->tokenize($value);
$syntaxTree = $this->parser->parse($tokenSequence);

$queryString = $this->generator->generate($syntaxTree);
$searchField = 'meta_content__name_s';

return "{!edismax v='{$this->escapeQuote($queryString)}' qf='{$searchField}' uf=-*}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,15 @@ services:
tags:
- {name: ibexa.search.solr.query.content.criterion.visitor}

Ibexa\Solr\Query\Content\CriterionVisitor\ContentName:
arguments:
$tokenizer: '@ibexa.solr.query.query_translator.galach.tokenizer'
$parser: '@ibexa.solr.query.query_translator.galach.parser'
$generator: '@ibexa.solr.query.query_translator.galach.generator.edismax'
tags:
- {name: ibexa.search.solr.query.content.criterion.visitor}
- {name: ibexa.search.solr.query.location.criterion.visitor}

# Location search
Ibexa\Solr\Query\Location\CriterionVisitor\Ancestor:
tags:
Expand Down

0 comments on commit 5f792d9

Please sign in to comment.