-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhance search customization (#2591)
* Merge ElasticSearch and Solr custom criterion, sort clause and aggregation. Criteria, sort clauses and aggregations don't depend on the search engine, only their visitors and other handlers do. --------- Co-authored-by: adriendupuis <[email protected]> Co-authored-by: Marek Nocoń <[email protected]>
- Loading branch information
1 parent
eb96ce9
commit c765208
Showing
39 changed files
with
333 additions
and
354 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
49 changes: 49 additions & 0 deletions
49
code_samples/search/custom/config/aggregation_services.yaml
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,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 } |
5 changes: 5 additions & 0 deletions
5
...sticsearch/config/criterion_services.yaml → ...rch/custom/config/criterion_services.yaml
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions
5
...icsearch/config/sort_clause_services.yaml → ...h/custom/config/sort_clause_services.yaml
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
42 changes: 42 additions & 0 deletions
42
code_samples/search/custom/src/EventSubscriber/CustomIndexDataSubscriber.php
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,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', | ||
]; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
code_samples/search/custom/src/EventSubscriber/CustomQueryFilterSubscriber.php
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,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', | ||
]; | ||
} | ||
} |
File renamed without changes.
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
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
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
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
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
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
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
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
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
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
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
File renamed without changes.
10 changes: 0 additions & 10 deletions
10
code_samples/search/elasticsearch/config/aggregation_services.yaml
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
...les/search/elasticsearch/src/Query/Aggregation/Elasticsearch/PriorityRangeAggregation.php
This file was deleted.
Oops, something went wrong.
36 changes: 0 additions & 36 deletions
36
...es/search/elasticsearch/src/Query/Criterion/Elasticsearch/CameraManufacturerCriterion.php
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
code_samples/search/elasticsearch/src/Query/SortClause/Elasticsearch/ScoreSortClause.php
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.