Skip to content

Commit

Permalink
Code review suggestions applied
Browse files Browse the repository at this point in the history
  • Loading branch information
kisztof committed Oct 27, 2023
1 parent 609a2c3 commit 3fc20a1
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,13 @@ private function addSuggestionConfiguration(): ArrayNodeDefinition
->addDefaultsIfNotSet()
->children()
->integerNode('min_query_length')
->info('The minimum length of the query string needed to trigger suggestions. Minimum value is 3.')
->isRequired()
->defaultValue(3)
->min(3)
->end()
->integerNode('result_limit')
->info('The maximum number of suggestion results to return. Minimum value is 5.')
->isRequired()
->defaultValue(5)
->min(5)
Expand Down
6 changes: 5 additions & 1 deletion src/bundle/Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ imports:
- { resource: twig.yaml }
- { resource: sorting_definitions.yaml }
- { resource: views.yaml }
- { resource: services/controllers.yaml }
- { resource: services/suggestions.yaml }
- { resource: services/normalizers.yaml }

Expand All @@ -13,6 +12,11 @@ services:
autowire: true
public: false

Ibexa\Bundle\PackageName\Controller\:
resource: './../../Controller'
tags:
- controller.service_arguments

Ibexa\Search\Mapper\PagerSearchContentToDataMapper:
arguments:
$contentTypeService: '@ibexa.api.service.content_type'
Expand Down
13 changes: 0 additions & 13 deletions src/bundle/Resources/config/services/controllers.yaml

This file was deleted.

4 changes: 2 additions & 2 deletions src/lib/Mapper/SearchHitToContentSuggestionMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ public function map(SearchHit $searchHit): ?ContentSuggestion
}

$parentsLocation = $mainLocation->path;
$position = array_search((string)$rootLocationId, $parentsLocation);
$position = array_search($rootLocationId, $parentsLocation, true);
if ($position !== false) {
$parentsLocation = array_slice($parentsLocation, (int)$position);
}

$parentCollection = $this->parentLocationProvider->provide($parentsLocation);

return new ContentSuggestion(
$searchHit->score ?? 50,
$searchHit->score ?? 50.0,
$content->getContentType()->identifier,
$content->getName() ?? '',
$content->getVersionInfo()->getContentInfo()->getId(),
Expand Down
4 changes: 1 addition & 3 deletions tests/lib/Mapper/SearchHitToContentSuggestionMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface;
use Ibexa\Contracts\Search\Model\Suggestion\ContentSuggestion;
use Ibexa\Contracts\Search\Model\Suggestion\ParentLocation;
use Ibexa\Contracts\Search\Model\Suggestion\ParentLocationCollection;
use Ibexa\Contracts\Search\Provider\ParentLocationProviderInterface as ParentLocationProviderInterface;
use Ibexa\Contracts\Search\Provider\ParentLocationProviderInterface;
use Ibexa\Core\Repository\Values\Content\Content;
use Ibexa\Core\Repository\Values\Content\Location;
use Ibexa\Core\Repository\Values\Content\VersionInfo;
Expand Down Expand Up @@ -64,7 +63,6 @@ public function testMap(): void
self::assertInstanceOf(ContentSuggestion::class, $result);
self::assertSame(1, $result->getContentId());
self::assertSame('5/6/7', $result->getPathString());
self::assertInstanceOf(ParentLocationCollection::class, $result->getParentLocations());
self::assertCount(3, $result->getParentLocations());
self::assertSame('name_eng', $result->getName());
self::assertSame(50.0, $result->getScore());
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/Service/Event/SuggestionServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function testSuggestion(): void
$service = new SuggestionService($innerServiceMock, $eventDispatcherMock);

$result = $service->suggest(new SuggestionQuery('query', 10, 'eng-GB'));
self::assertInstanceOf(SuggestionCollection::class, $result);
self::assertCount(0, $result);
}

public function testSuggestionStopPropagation(): void
Expand All @@ -68,7 +68,7 @@ static function (BeforeSuggestionEvent $event): BeforeSuggestionEvent {
$service = new SuggestionService($innerServiceMock, $eventDispatcherMock);

$result = $service->suggest(new SuggestionQuery('query', 10, 'eng-GB'));
self::assertInstanceOf(SuggestionCollection::class, $result);
self::assertCount(0, $result);
}

/**
Expand Down
3 changes: 1 addition & 2 deletions tests/lib/Service/SuggestionServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

namespace Ibexa\Tests\Search\Service;

use Ibexa\Contracts\Search\Model\Suggestion\SuggestionCollection;
use Ibexa\Search\Model\SuggestionQuery;
use Ibexa\Search\Service\SuggestionService;
use PHPUnit\Framework\TestCase;
Expand All @@ -26,7 +25,7 @@ public function testSuggestion(): void
$service = new SuggestionService($eventDispatcherMock);
$result = $service->suggest(new SuggestionQuery('query', 10, 'eng-GB'));

self::assertInstanceOf(SuggestionCollection::class, $result);
self::assertCount(0, $result);
}

/**
Expand Down

0 comments on commit 3fc20a1

Please sign in to comment.