Skip to content

Commit

Permalink
Merge ElasticSearch and Solr custom criterion, sort clause and aggreg…
Browse files Browse the repository at this point in the history
…ation

Criteria, sort clauses and aggregations don't depend on the search engine, only their visitors and other handlers do.
  • Loading branch information
adriendupuis committed Jan 11, 2025
1 parent 7a05c67 commit 4028a27
Show file tree
Hide file tree
Showing 33 changed files with 137 additions and 216 deletions.
57 changes: 57 additions & 0 deletions code_samples/search/custom/config/aggregation_services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
services:
app.search.solr.query.aggregation_visitor.priority_range_aggregation:
class: Ibexa\Solr\Query\Common\AggregationVisitor\PriorityRangeAggregationVisitor
factory: [ '@Ibexa\Solr\Query\Common\AggregationVisitor\Factory\ContentFieldAggregationVisitorFactory', 'createRangeAggregationVisitor' ]
arguments:
$aggregationClass: 'App\Query\Aggregation\Solr\PriorityRangeAggregation'
$searchIndexFieldName: 'priority_i'
tags:
- { name: ibexa.search.solr.query.content.aggregation.visitor }
- { name: ibexa.search.solr.query.location.aggregation.visitor }

app.search.elasticsearch.query.aggregation_visitor.priority_range_aggregation:
class: Ibexa\Elasticsearch\Query\AggregationVisitor\PriorityRangeAggregationVisitor
factory: [ '@Ibexa\Elasticsearch\Query\AggregationVisitor\Factory\SearchFieldAggregationVisitorFactory', 'createRangeAggregationVisitor' ]
arguments:
$aggregationClass: 'App\Query\Aggregation\Elasticsearch\PriorityRangeAggregation'
$searchIndexFieldName: 'priority_i'
tags:
- { name: ibexa.search.elasticsearch.query.location.aggregation.visitor }
- { name: ibexa.search.elasticsearch.query.content.aggregation.visitor }

app.search.solr.query.aggregation_result_extractor.priority_range_aggregation:
class: Ibexa\Solr\ResultExtractor\AggregationResultExtractor\RangeAggregationResultExtractor
arguments:
$aggregationClass: 'App\Query\Aggregation\Solr\PriorityRangeAggregation'
$keyMapper: 'Ibexa\Solr\ResultExtractor\AggregationResultExtractor\RangeAggregationKeyMapper\IntRangeAggregationKeyMapper'
tags:
- { name: ibexa.search.solr.query.location.aggregation.result.extractor }
- { name: ibexa.search.solr.query.content.aggregation.result.extractor }

app.search.elasticsearch.query.aggregation_result_extractor.priority_range_aggregation:
class: Ibexa\Elasticsearch\Query\ResultExtractor\AggregationResultExtractor\RangeAggregationResultExtractor
arguments:
$aggregationClass: 'App\Query\Aggregation\Elasticsearch\PriorityRangeAggregation'
tags:
- { name: ibexa.search.elasticsearch.query.location.aggregation.result.extractor }
- { name: ibexa.search.elasticsearch.query.content.aggregation.result.extractor }

App\Query\Aggregation\Solr\PriorityRangeAggregationVisitor:
tags:
- { name: ibexa.search.solr.query.location.aggregation.visitor }
- { name: ibexa.search.solr.query.content.aggregation.visitor }

App\Query\Aggregation\Solr\PriorityRangeAggregationResultExtractor:
tags:
- { name: ibexa.search.solr.query.location.aggregation.result.extractor }
- { name: ibexa.search.solr.query.content.aggregation.result.extractor }

App\Query\Aggregation\Elasticsearch\PriorityRangeAggregationVisitor:
tags:
- { name: ibexa.search.elasticsearch.query.location.aggregation.visitor }
- { name: ibexa.search.elasticsearch.query.content.aggregation.visitor }

App\Query\Aggregation\Elasticsearch\PriorityRangeAggregationResultExtractor:
tags:
- { name: ibexa.search.elasticsearch.query.location.aggregation.result.extractor }
- { name: ibexa.search.elasticsearch.query.content.aggregation.result.extractor }
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
services:
App\Query\Criterion\Solr\CameraManufacturerVisitor:
tags:
- { name: ibexa.search.solr.query.content.criterion.visitor }
- { name: ibexa.search.solr.query.location.criterion.visitor }

App\Query\Criterion\Elasticsearch\CameraManufacturerVisitor:
tags:
- { name: ibexa.search.elasticsearch.query.content.criterion.visitor }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
services:
App\Query\SortClause\Solr\ScoreVisitor:
tags:
- { name: ibexa.search.solr.query.content.sort_clause.visitor }
- { name: ibexa.search.solr.query.location.sort_clause.visitor }

App\Query\SortClause\Elasticsearch\ScoreVisitor:
tags:
- { name: ibexa.search.elasticsearch.query.content.sort_clause.visitor }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

namespace App\Query\Aggregation\Elasticsearch;

use App\Query\Aggregation\PriorityRangeAggregation;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation;
use Ibexa\Contracts\Core\Repository\Values\Content\Search\AggregationResult;
use Ibexa\Contracts\Elasticsearch\Query\AggregationResultExtractor;
use Ibexa\Contracts\Elasticsearch\Query\LanguageFilter;

final class PriorityAggregationResultExtractor implements AggregationResultExtractor
final class PriorityRangeAggregationResultExtractor implements AggregationResultExtractor
{
public function supports(Aggregation $aggregation, LanguageFilter $languageFilter): bool
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

namespace App\Query\Aggregation\Elasticsearch;

use App\Query\Aggregation\PriorityRangeAggregation;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation;
use Ibexa\Contracts\Elasticsearch\Query\AggregationVisitor;
use Ibexa\Contracts\Elasticsearch\Query\LanguageFilter;

final class PriorityAggregationVisitor implements AggregationVisitor
final class PriorityRangeAggregationVisitor implements AggregationVisitor
{
public function supports(Aggregation $aggregation, LanguageFilter $languageFilter): bool
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Query\Aggregation\Solr;
namespace App\Query\Aggregation;

use Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\AbstractRangeAggregation;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\LocationAggregation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Query\Aggregation\Solr;

use App\Query\Aggregation\PriorityRangeAggregation;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\Range;
use Ibexa\Contracts\Core\Repository\Values\Content\Search\AggregationResult;
Expand All @@ -12,7 +13,7 @@
use Ibexa\Contracts\Solr\ResultExtractor\AggregationResultExtractor;
use stdClass;

final class PriorityAggregationResultExtractor implements AggregationResultExtractor
final class PriorityRangeAggregationResultExtractor implements AggregationResultExtractor
{
public function canVisit(Aggregation $aggregation, array $languageFilter): bool

Check failure on line 18 in code_samples/search/custom/src/Query/Aggregation/Solr/PriorityRangeAggregationResultExtractor.php

View workflow job for this annotation

GitHub Actions / Validate code samples (8.3)

Method App\Query\Aggregation\Solr\PriorityRangeAggregationResultExtractor::canVisit() has parameter $languageFilter with no value type specified in iterable type array.
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Query\Aggregation\Solr;

use App\Query\Aggregation\PriorityRangeAggregation;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation;
use Ibexa\Contracts\Solr\Query\AggregationVisitor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Query\Criterion\Solr;
namespace App\Query\Criterion;

use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\Operator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Query\Criterion\Elasticsearch;

use App\Query\Criterion\CameraManufacturerCriterion;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\CriterionInterface;
use Ibexa\Contracts\Elasticsearch\Query\CriterionVisitor;
use Ibexa\Contracts\Elasticsearch\Query\LanguageFilter;
Expand All @@ -16,7 +17,7 @@ public function supports(CriterionInterface $criterion, LanguageFilter $language
}

/**
* @param \App\Query\Criterion\Elasticsearch\CameraManufacturerCriterion $criterion
* @param \App\Query\Criterion\CameraManufacturerCriterion $criterion
*/
public function visit(CriterionVisitor $dispatcher, CriterionInterface $criterion, LanguageFilter $languageFilter): array

Check failure on line 22 in code_samples/search/custom/src/Query/Criterion/Elasticsearch/CameraManufacturerVisitor.php

View workflow job for this annotation

GitHub Actions / Validate code samples (8.3)

Method App\Query\Criterion\Elasticsearch\CameraManufacturerVisitor::visit() return type has no value type specified in iterable type array.
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Query\Criterion\Solr;

use App\Query\Criterion\CameraManufacturerCriterion;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\CriterionInterface;
use Ibexa\Contracts\Solr\Query\CriterionVisitor;

Expand All @@ -15,7 +16,7 @@ public function canVisit(CriterionInterface $criterion)
}

/**
* @param \App\Query\Criterion\Solr\CameraManufacturerCriterion $criterion
* @param \App\Query\Criterion\CameraManufacturerCriterion $criterion
*/
public function visit(CriterionInterface $criterion, CriterionVisitor $subVisitor = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Query\SortClause\Elasticsearch;

use App\Query\SortClause\ScoreSortClause;
use Ibexa\Contracts\Core\Repository\Values\Content\Query;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\SortClause;
use Ibexa\Contracts\Elasticsearch\Query\LanguageFilter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Query\SortClause\Solr;
namespace App\Query\SortClause;

use Ibexa\Contracts\Core\Repository\Values\Content\Query;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\SortClause;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

namespace App\Query\SortClause\Solr;

use App\Query\SortClause\ScoreSortClause;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\SortClause;
use Ibexa\Contracts\Solr\Query\SortClauseVisitor;

class ScoreVisitor extends SortClauseVisitor
{
public function canVisit(SortClause $sortClause): bool
{
return $sortClause instanceof SortClause\Score;
return $sortClause instanceof ScoreSortClause;
}

public function visit(SortClause $sortClause): string
Expand Down
10 changes: 0 additions & 10 deletions code_samples/search/elasticsearch/config/aggregation_services.yaml

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

10 changes: 0 additions & 10 deletions code_samples/search/solr/config/aggregation_services.yaml

This file was deleted.

5 changes: 0 additions & 5 deletions code_samples/search/solr/config/criterion_services.yaml

This file was deleted.

5 changes: 0 additions & 5 deletions code_samples/search/solr/config/sort_clause_services.yaml

This file was deleted.

Loading

0 comments on commit 4028a27

Please sign in to comment.