Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance search customization #2591

Merged
merged 33 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4028a27
Merge ElasticSearch and Solr custom criterion, sort clause and aggreg…
adriendupuis Jan 11, 2025
0cfc503
PHP CS Fixes
adriendupuis Jan 11, 2025
30a9151
Update phpstan-baseline.neon
adriendupuis Jan 11, 2025
b7dd166
Update phpstan-baseline.neon
adriendupuis Jan 11, 2025
d44d436
Update phpstan-baseline.neon
adriendupuis Jan 11, 2025
ec0c31f
aggregation_services.yaml: Fix base visitor classes
adriendupuis Jan 12, 2025
cedc245
aggregation_services.yaml: Fix priority_range_aggregation factory
adriendupuis Jan 13, 2025
497b243
create_custom_search_criterion.md: Links to custom index pages
adriendupuis Feb 7, 2025
65ede71
create_custom_aggregation.md: Add a class section
adriendupuis Feb 7, 2025
e162148
create_custom_aggregation.md: Narrow usage to location
adriendupuis Feb 7, 2025
a8cd54e
create_custom_aggregation.md: Introduce Solr's $keyMapper
adriendupuis Feb 7, 2025
e160ab1
create_custom_aggregation.md: Sort aggregation types
adriendupuis Feb 7, 2025
4df9600
create_custom_aggregation.md: Add links to PHP API Ref, Fix FQCN
adriendupuis Feb 7, 2025
bb2894c
solr_document_field_mappers.md: Links to PHP API Ref
adriendupuis Feb 10, 2025
5bab11a
index_custom_elasticsearch_data.md: Links to PHP API Ref
adriendupuis Feb 10, 2025
e5c9500
index_custom_elasticsearch_data.md: Links to PHP API Ref
adriendupuis Feb 10, 2025
5886003
index_custom_elasticsearch_data.md: service registration is not manda…
adriendupuis Feb 10, 2025
04c0c79
customize_elasticsearch_index_structure.md: Indicate CompositeGroupRe…
adriendupuis Feb 10, 2025
60188d9
manipulate_elasticsearch_query.md: Link to PHP API Ref
adriendupuis Feb 10, 2025
474dd36
manipulate_elasticsearch_query.md: Fix redundancy
adriendupuis Feb 10, 2025
3f7c13c
manipulate_elasticsearch_query.md: service registration is not mandatory
adriendupuis Feb 10, 2025
ad59fb7
Move Elasticsearch subscribers to code_samples/ PHP files
adriendupuis Feb 10, 2025
e40ce72
PHP CS Fixes
adriendupuis Feb 10, 2025
43e98f8
build.yaml: Avoid too long code_samples_usage.diff.md
adriendupuis Feb 10, 2025
a98cdab
Merge branch 'master' into enh-custom-search
adriendupuis Feb 10, 2025
3433f9b
build.yaml: Avoid too long code_samples_usage.diff.md
adriendupuis Feb 10, 2025
e15db11
create_custom_aggregation.md: Explain why only location tag, fix tag.
adriendupuis Feb 10, 2025
9ee8733
Merge branch 'master' into enh-custom-search
adriendupuis Feb 11, 2025
2dbf67b
build.yaml: Avoid too long code_samples_usage.diff.md
adriendupuis Feb 11, 2025
5aef3cb
build.yaml: Avoid too long code_samples_usage.diff.md
adriendupuis Feb 11, 2025
130f30b
build.yaml: Avoid too long code_samples_usage.diff.md
adriendupuis Feb 11, 2025
8159cde
search/extensibility/*.md: Symfony's autoconfiguration
adriendupuis Feb 11, 2025
8da31d0
Apply suggestions from code review
adriendupuis Feb 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,19 @@ jobs:
- name: Convert code_samples usages for comment
if: steps.list.outputs.CODE_SAMPLES_CHANGE != '' && steps.diff.outputs.CODE_SAMPLES_DIFF != '0'
run: |
echo '# code_samples/ change report' >> code_samples_usage.diff.md
title='# code_samples/ change report'
link='<a href="${{ steps.artifact.outputs.artifact-url }}">Download colorized diff</a>'
echo "$title" > code_samples_usage.diff.md
echo '' >> code_samples_usage.diff.md
php tools/code_samples/code_samples_usage_diff2html.php $HOME/code_samples_usage.diff >> code_samples_usage.diff.md
echo '<a href="${{ steps.artifact.outputs.artifact-url }}">Download colorized diff</a>' >> code_samples_usage.diff.md
echo "$link" >> code_samples_usage.diff.md
if [[ `wc -m < code_samples_usage.diff.md | xargs` -ge $((2**16)) ]]; then
adriendupuis marked this conversation as resolved.
Show resolved Hide resolved
echo "$title" > code_samples_usage.diff.md
echo '' >> code_samples_usage.diff.md
echo "Report's diff is too long to be displayed in a comment." >> code_samples_usage.diff.md
echo '' >> code_samples_usage.diff.md
echo "$link" >> code_samples_usage.diff.md
fi
- name: Find Comment
id: find-comment
uses: peter-evans/find-comment@v3
Expand Down
49 changes: 49 additions & 0 deletions code_samples/search/custom/config/aggregation_services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
services:
app.search.solr.query.aggregation_visitor.priority_range_aggregation:
class: Ibexa\Solr\Query\Common\AggregationVisitor\RangeAggregationVisitor
factory: [ '@Ibexa\Solr\Query\Common\AggregationVisitor\Factory\SearchFieldAggregationVisitorFactory', 'createRangeAggregationVisitor' ]
arguments:
$aggregationClass: 'App\Query\Aggregation\Solr\PriorityRangeAggregation'
$searchIndexFieldName: 'priority_i'
tags:
- { name: ibexa.search.solr.query.location.aggregation.visitor }

app.search.elasticsearch.query.aggregation_visitor.priority_range_aggregation:
class: Ibexa\Elasticsearch\Query\AggregationVisitor\RangeAggregationVisitor
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 }

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 }

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 }

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

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

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

App\Query\Aggregation\Elasticsearch\PriorityRangeAggregationResultExtractor:
tags:
- { name: ibexa.search.elasticsearch.query.location.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
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace App\EventSubscriber;

use Ibexa\Contracts\Core\Search\Field;
use Ibexa\Contracts\Core\Search\FieldType\StringField;
use Ibexa\Contracts\Elasticsearch\Mapping\Event\ContentIndexCreateEvent;
use Ibexa\Contracts\Elasticsearch\Mapping\Event\LocationIndexCreateEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

final class CustomIndexDataSubscriber implements EventSubscriberInterface
{
public function onContentDocumentCreate(ContentIndexCreateEvent $event): void
{
$document = $event->getDocument();
$document->fields[] = new Field(
'custom_field',
'Custom field value',
new StringField()
);
}

public function onLocationDocumentCreate(LocationIndexCreateEvent $event): void
{
$document = $event->getDocument();
$document->fields[] = new Field(
'custom_field',
'Custom field value',
new StringField()
);
}

public static function getSubscribedEvents(): array
{
return [
ContentIndexCreateEvent::class => 'onContentDocumentCreate',
LocationIndexCreateEvent::class => 'onLocationDocumentCreate',
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace App\EventSubscriber;

use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\LogicalAnd;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\ObjectStateIdentifier;
use Ibexa\Contracts\ElasticSearch\Query\Event\QueryFilterEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

final class CustomQueryFilterSubscriber implements EventSubscriberInterface
{
public function onQueryFilter(QueryFilterEvent $event): void
{
$query = $event->getQuery();

$additionalCriteria = new ObjectStateIdentifier('locked');

if ($query->filter !== null) {
$query->filter = $additionalCriteria;
} else {
// Append Criterion to existing filter
$query->filter = new LogicalAnd([
$query->filter,
$additionalCriteria,
]);
}
}

public static function getSubscribedEvents(): array
{
return [
QueryFilterEvent::class => 'onQueryFilter',
];
}
}
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,19 +4,20 @@

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
{
return $aggregation instanceof PriorityRangeAggregation;
}

/**
* @param PriorityRangeAggregation $aggregation
* @param \App\Query\Aggregation\PriorityRangeAggregation $aggregation
*/
public function visit(AggregationVisitor $dispatcher, Aggregation $aggregation, LanguageFilter $languageFilter): array
{
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
{
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
{
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.

Loading
Loading