Skip to content

Commit d0e9279

Browse files
committed
IBX-7462: Removed "Top Level Nodes" from breadcrumbs in search suggestions
1 parent f252988 commit d0e9279

File tree

2 files changed

+53
-15
lines changed

2 files changed

+53
-15
lines changed

src/lib/Mapper/SearchHitToContentSuggestionMapper.php

+7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
final class SearchHitToContentSuggestionMapper implements SearchHitToContentSuggestionMapperInterface
1919
{
20+
private const ROOT_LOCATION_ID = 1;
21+
2022
private ConfigResolverInterface $configResolver;
2123

2224
private ParentLocationProviderInterface $parentLocationProvider;
@@ -51,6 +53,11 @@ public function map(SearchHit $searchHit): ?ContentSuggestion
5153
$parentsLocation = array_slice($parentsLocation, (int)$position);
5254
}
5355

56+
if (reset($parentsLocation) === self::ROOT_LOCATION_ID) {
57+
// Remove "Top Level Nodes" from suggestion path
58+
array_shift($parentsLocation);
59+
}
60+
5461
$parentLocations = $this->parentLocationProvider->provide($parentsLocation);
5562

5663
return new ContentSuggestion(

tests/lib/Mapper/SearchHitToContentSuggestionMapperTest.php

+46-15
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,51 @@ public function testMap(): void
2929
$this->getConfigResolverMock()
3030
);
3131

32-
$content = new Content([
32+
$content = $this->createContentWithLocationPath(['1', '2', '3', '4', '5', '6', '7']);
33+
34+
$result = $mapper->map(
35+
new SearchHit([
36+
'valueObject' => $content,
37+
])
38+
);
39+
40+
self::assertInstanceOf(ContentSuggestion::class, $result);
41+
self::assertSame($content, $result->getContent());
42+
self::assertSame('5/6/7', $result->getPathString());
43+
self::assertCount(3, $result->getParentsLocation());
44+
self::assertSame('name_eng', $result->getName());
45+
self::assertSame(50.0, $result->getScore());
46+
}
47+
48+
public function testMapContentOutsideRootLocation(): void
49+
{
50+
$mapper = new SearchHitToContentSuggestionMapper(
51+
$this->getParentLocationProviderMock(),
52+
$this->getConfigResolverMock()
53+
);
54+
55+
$content = $this->createContentWithLocationPath(['1', '2', '3', '4', '6', '7']);
56+
57+
$result = $mapper->map(
58+
new SearchHit([
59+
'valueObject' => $content,
60+
])
61+
);
62+
63+
self::assertInstanceOf(ContentSuggestion::class, $result);
64+
self::assertSame($content, $result->getContent());
65+
self::assertSame('2/3/4/6/7', $result->getPathString());
66+
self::assertCount(5, $result->getParentsLocation());
67+
self::assertSame('name_eng', $result->getName());
68+
self::assertSame(50.0, $result->getScore());
69+
}
70+
71+
/**
72+
* @param string[] $path
73+
*/
74+
private function createContentWithLocationPath(array $path): Content
75+
{
76+
return new Content([
3377
'id' => 1,
3478
'contentInfo' => new ContentInfo([
3579
'name' => 'name',
@@ -46,27 +90,14 @@ public function testMap(): void
4690
'contentTypeId' => 1,
4791
'mainLocation' => new Location([
4892
'id' => 8,
49-
'path' => ['1', '2', '3', '4', '5', '6', '7'],
93+
'path' => $path,
5094
]),
5195
]),
5296
]),
5397
'contentType' => new ContentType([
5498
'identifier' => 'content_type_identifier',
5599
]),
56100
]);
57-
58-
$result = $mapper->map(
59-
new SearchHit([
60-
'valueObject' => $content,
61-
])
62-
);
63-
64-
self::assertInstanceOf(ContentSuggestion::class, $result);
65-
self::assertSame($content, $result->getContent());
66-
self::assertSame('5/6/7', $result->getPathString());
67-
self::assertCount(3, $result->getParentsLocation());
68-
self::assertSame('name_eng', $result->getName());
69-
self::assertSame(50.0, $result->getScore());
70101
}
71102

72103
/**

0 commit comments

Comments
 (0)