Skip to content

Commit

Permalink
NGSTACK-843 improved configuration builder and added tests for page i…
Browse files Browse the repository at this point in the history
…ndexing configuration
  • Loading branch information
Katarina Miočić committed Apr 19, 2024
1 parent bee2cf8 commit 9972c2d
Show file tree
Hide file tree
Showing 4 changed files with 369 additions and 16 deletions.
70 changes: 65 additions & 5 deletions bundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,29 +90,89 @@ private function addUsePageIndexingSection(ArrayNodeDefinition $nodeDefinition):

private function addPageIndexingSection(ArrayNodeDefinition $nodeDefinition): void
{
$keyValidator = static function ($v) {
foreach (array_keys($v) as $key) {
if (!is_string($key)) {
return true;
}
}
return false;
};
$nodeDefinition
->children()
->arrayNode('page_indexing')
->info('Page indexing configuration')
->children()
->arrayNode('site_roots')
->scalarPrototype()->end()
->info('Location ids of site roots')
->info('Site root ids')
->useAttributeAsKey('name')
->normalizeKeys(false)
->validate()
->ifTrue($keyValidator)
->thenInvalid('Site root name must be of string type.')
->end()
->integerPrototype()
->beforeNormalization()->always(static fn ($v) => is_string($v) ? (int)$v : $v)->end()
->info('Content ID')
->end()
->end()
->arrayNode('languages_siteaccess_map')
->info('Language key mapped to page siteaccess')
->useAttributeAsKey('name')
->normalizeKeys(false)
->validate()
->ifTrue($keyValidator)
->thenInvalid('Page name must be of string type.')
->end()
->prototype('array')
->prototype('scalar')->end()
->useAttributeAsKey('name')
->normalizeKeys(false)
->validate()
->ifTrue($keyValidator)
->thenInvalid('Language code must be of string type.')
->end()
->prototype('scalar')
->validate()
->ifTrue(static fn ($v) => !is_string($v))
->thenInvalid('Siteaccess name must be of string type.')
->end()
->end()
->end()
->end()
->scalarNode('host')
->info('Host to index page from, defined in .env files')
->validate()
->ifTrue(static fn ($v) => !is_string($v))
->thenInvalid('Host must be of string type.')
->end()
->end()
->arrayNode('config')
->info('Config for separating page text by importance of the html tags and classes, used to index content to separate solr fields')
->validate()
->ifTrue($keyValidator)
->thenInvalid('Array key (level of field importance) must be of string type.')
->end()
->prototype('array')
->prototype('scalar')->end()
->useAttributeAsKey('name')
->normalizeKeys(false)
->scalarPrototype()
->validate()
->ifTrue(static fn ($v) => !is_string($v))
->thenInvalid('HTML tag and class must be of string type.')
->end()
->end()
->end()
->end()
->arrayNode('allowed_content_types')
->scalarPrototype()->end()
->info('Content types to index')
->useAttributeAsKey('name')
->normalizeKeys(false)
->scalarPrototype()
->validate()
->ifTrue(static fn ($v) => !is_string($v))
->thenInvalid('Content type identifier must be of string type.')
->end()
->end()
->end()
->end()
->end();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ private function processUsePageIndexingConfiguration(array $configuration, Conta

private function processPageIndexingConfiguration(array $configuration, ContainerBuilder $container): void
{

$container->setParameter(
'netgen_ibexa_search_extra.page_indexing.site_roots',
$configuration['page_indexing']['site_roots'] ?? [],
Expand All @@ -138,7 +139,7 @@ private function processPageIndexingConfiguration(array $configuration, Containe
);
$container->setParameter(
'netgen_ibexa_search_extra.page_indexing.host',
$configuration['page_indexing']['host'] ?? [],
$configuration['page_indexing']['host'] ?? null,
);
$container->setParameter(
'netgen_ibexa_search_extra.page_indexing.config',
Expand Down
20 changes: 10 additions & 10 deletions lib/Resources/config/search/common/layouts_page_text_indexing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ services:
- '@Ibexa\Contracts\Core\Persistence\Content\Handler'
- '@Ibexa\Contracts\Core\Persistence\Content\Location\Handler'
- '@Symfony\Component\Routing\RouterInterface'
- '%netgen.ibexa_search_extra.page_indexing.site_roots%'
- '%netgen.ibexa_search_extra.page_indexing.languages_siteaccess_map%'
- '%netgen.ibexa_search_extra.page_indexing.host%'
- '%netgen.ibexa_search_extra.page_indexing.config%'
- '%netgen_ibexa_search_extra.page_indexing.site_roots%'
- '%netgen_ibexa_search_extra.page_indexing.languages_siteaccess_map%'
- '%netgen_ibexa_search_extra.page_indexing.host%'
- '%netgen_ibexa_search_extra.page_indexing.config%'
calls:
- setLogger: ['@?logger']

Expand All @@ -22,9 +22,9 @@ services:
- '@ibexa.api.persistence_handler'
- '%netgen.ibexa_search_extra.page_indexing.allowed_content_types%'

parameters:
netgen.ibexa_search_extra.page_indexing.site_roots: []
netgen.ibexa_search_extra.page_indexing.languages_siteaccess_map: []
netgen.ibexa_search_extra.page_indexing.host: null
netgen.ibexa_search_extra.page_indexing.config: []
netgen.ibexa_search_extra.page_indexing.allowed_content_types: []
#parameters:
# netgen.ibexa_search_extra.page_indexing.site_roots: []
# netgen.ibexa_search_extra.page_indexing.languages_siteaccess_map: []
# netgen.ibexa_search_extra.page_indexing.host: null
# netgen.ibexa_search_extra.page_indexing.config: []
# netgen.ibexa_search_extra.page_indexing.allowed_content_types: []
Loading

0 comments on commit 9972c2d

Please sign in to comment.