-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added CriterionVisitor for ContentNameCriterion
- Loading branch information
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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=-*}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters