Skip to content

Commit e06b15a

Browse files
adriendupuismnocon
andcommitted
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. (cherry picked from commit c765208) --------- Co-authored-by: adriendupuis <[email protected]> Co-authored-by: Marek Nocoń <[email protected]>
1 parent 49d1f0d commit e06b15a

File tree

39 files changed

+337
-352
lines changed

39 files changed

+337
-352
lines changed

.github/workflows/build.yaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,19 @@ jobs:
182182
- name: Convert code_samples usages for comment
183183
if: steps.list.outputs.CODE_SAMPLES_CHANGE != '' && steps.diff.outputs.CODE_SAMPLES_DIFF != '0'
184184
run: |
185-
echo '# code_samples/ change report' >> code_samples_usage.diff.md
185+
title='# code_samples/ change report'
186+
link='<a href="${{ steps.artifact.outputs.artifact-url }}">Download colorized diff</a>'
187+
echo "$title" > code_samples_usage.diff.md
186188
echo '' >> code_samples_usage.diff.md
187189
php tools/code_samples/code_samples_usage_diff2html.php $HOME/code_samples_usage.diff >> code_samples_usage.diff.md
188-
echo '<a href="${{ steps.artifact.outputs.artifact-url }}">Download colorized diff</a>' >> code_samples_usage.diff.md
190+
echo "$link" >> code_samples_usage.diff.md
191+
if [[ `wc -m < code_samples_usage.diff.md | xargs` -ge $((2**16)) ]]; then
192+
echo "$title" > code_samples_usage.diff.md
193+
echo '' >> code_samples_usage.diff.md
194+
echo "Report's diff is too long to be displayed in a comment." >> code_samples_usage.diff.md
195+
echo '' >> code_samples_usage.diff.md
196+
echo "$link" >> code_samples_usage.diff.md
197+
fi
189198
- name: Find Comment
190199
id: find-comment
191200
uses: peter-evans/find-comment@v3
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
services:
2+
app.search.solr.query.aggregation_visitor.priority_range_aggregation:
3+
class: Ibexa\Solr\Query\Common\AggregationVisitor\RangeAggregationVisitor
4+
factory: [ '@Ibexa\Solr\Query\Common\AggregationVisitor\Factory\SearchFieldAggregationVisitorFactory', 'createRangeAggregationVisitor' ]
5+
arguments:
6+
$aggregationClass: 'App\Query\Aggregation\Solr\PriorityRangeAggregation'
7+
$searchIndexFieldName: 'priority_i'
8+
tags:
9+
- { name: ibexa.search.solr.query.location.aggregation.visitor }
10+
11+
app.search.elasticsearch.query.aggregation_visitor.priority_range_aggregation:
12+
class: Ibexa\Elasticsearch\Query\AggregationVisitor\RangeAggregationVisitor
13+
factory: [ '@Ibexa\Elasticsearch\Query\AggregationVisitor\Factory\SearchFieldAggregationVisitorFactory', 'createRangeAggregationVisitor' ]
14+
arguments:
15+
$aggregationClass: 'App\Query\Aggregation\Elasticsearch\PriorityRangeAggregation'
16+
$searchIndexFieldName: 'priority_i'
17+
tags:
18+
- { name: ibexa.search.elasticsearch.query.location.aggregation.visitor }
19+
20+
app.search.solr.query.aggregation_result_extractor.priority_range_aggregation:
21+
class: Ibexa\Solr\ResultExtractor\AggregationResultExtractor\RangeAggregationResultExtractor
22+
arguments:
23+
$aggregationClass: 'App\Query\Aggregation\Solr\PriorityRangeAggregation'
24+
$keyMapper: 'Ibexa\Solr\ResultExtractor\AggregationResultExtractor\RangeAggregationKeyMapper\IntRangeAggregationKeyMapper'
25+
tags:
26+
- { name: ibexa.search.solr.query.location.aggregation.result.extractor }
27+
28+
app.search.elasticsearch.query.aggregation_result_extractor.priority_range_aggregation:
29+
class: Ibexa\Elasticsearch\Query\ResultExtractor\AggregationResultExtractor\RangeAggregationResultExtractor
30+
arguments:
31+
$aggregationClass: 'App\Query\Aggregation\Elasticsearch\PriorityRangeAggregation'
32+
tags:
33+
- { name: ibexa.search.elasticsearch.query.location.aggregation.result.extractor }
34+
35+
App\Query\Aggregation\Solr\PriorityRangeAggregationVisitor:
36+
tags:
37+
- { name: ibexa.search.solr.query.location.aggregation.visitor }
38+
39+
App\Query\Aggregation\Solr\PriorityRangeAggregationResultExtractor:
40+
tags:
41+
- { name: ibexa.search.solr.query.location.aggregation.result.extractor }
42+
43+
App\Query\Aggregation\Elasticsearch\PriorityRangeAggregationVisitor:
44+
tags:
45+
- { name: ibexa.search.elasticsearch.query.location.aggregation.visitor }
46+
47+
App\Query\Aggregation\Elasticsearch\PriorityRangeAggregationResultExtractor:
48+
tags:
49+
- { name: ibexa.search.elasticsearch.query.location.aggregation.result.extractor }

code_samples/search/elasticsearch/config/criterion_services.yaml renamed to code_samples/search/custom/config/criterion_services.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
services:
2+
App\Query\Criterion\Solr\CameraManufacturerVisitor:
3+
tags:
4+
- { name: ibexa.search.solr.query.content.criterion.visitor }
5+
- { name: ibexa.search.solr.query.location.criterion.visitor }
6+
27
App\Query\Criterion\Elasticsearch\CameraManufacturerVisitor:
38
tags:
49
- { name: ibexa.search.elasticsearch.query.content.criterion.visitor }

code_samples/search/elasticsearch/config/sort_clause_services.yaml renamed to code_samples/search/custom/config/sort_clause_services.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
services:
2+
App\Query\SortClause\Solr\ScoreVisitor:
3+
tags:
4+
- { name: ibexa.search.solr.query.content.sort_clause.visitor }
5+
- { name: ibexa.search.solr.query.location.sort_clause.visitor }
6+
27
App\Query\SortClause\Elasticsearch\ScoreVisitor:
38
tags:
49
- { name: ibexa.search.elasticsearch.query.content.sort_clause.visitor }
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\EventSubscriber;
6+
7+
use Ibexa\Contracts\Core\Search\Field;
8+
use Ibexa\Contracts\Core\Search\FieldType\StringField;
9+
use Ibexa\Contracts\Elasticsearch\Mapping\Event\ContentIndexCreateEvent;
10+
use Ibexa\Contracts\Elasticsearch\Mapping\Event\LocationIndexCreateEvent;
11+
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
12+
13+
final class CustomIndexDataSubscriber implements EventSubscriberInterface
14+
{
15+
public function onContentDocumentCreate(ContentIndexCreateEvent $event): void
16+
{
17+
$document = $event->getDocument();
18+
$document->fields[] = new Field(
19+
'custom_field',
20+
'Custom field value',
21+
new StringField()
22+
);
23+
}
24+
25+
public function onLocationDocumentCreate(LocationIndexCreateEvent $event): void
26+
{
27+
$document = $event->getDocument();
28+
$document->fields[] = new Field(
29+
'custom_field',
30+
'Custom field value',
31+
new StringField()
32+
);
33+
}
34+
35+
public static function getSubscribedEvents(): array
36+
{
37+
return [
38+
ContentIndexCreateEvent::class => 'onContentDocumentCreate',
39+
LocationIndexCreateEvent::class => 'onLocationDocumentCreate',
40+
];
41+
}
42+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\EventSubscriber;
6+
7+
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\LogicalAnd;
8+
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\ObjectStateIdentifier;
9+
use Ibexa\Contracts\ElasticSearch\Query\Event\QueryFilterEvent;
10+
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
11+
12+
final class CustomQueryFilterSubscriber implements EventSubscriberInterface
13+
{
14+
public function onQueryFilter(QueryFilterEvent $event): void
15+
{
16+
$query = $event->getQuery();
17+
18+
$additionalCriteria = new ObjectStateIdentifier('locked');
19+
20+
if ($query->filter !== null) {
21+
$query->filter = $additionalCriteria;
22+
} else {
23+
// Append Criterion to existing filter
24+
$query->filter = new LogicalAnd([
25+
$query->filter,
26+
$additionalCriteria,
27+
]);
28+
}
29+
}
30+
31+
public static function getSubscribedEvents(): array
32+
{
33+
return [
34+
QueryFilterEvent::class => 'onQueryFilter',
35+
];
36+
}
37+
}

0 commit comments

Comments
 (0)