Skip to content

Commit 60a4f9d

Browse files
Search index adjustments (statamic#1546)
1 parent b54b546 commit 60a4f9d

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

app/Search/DocTransformer.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,19 @@
88

99
class DocTransformer implements DocumentTransformer
1010
{
11+
private function normalizeConent($value)
12+
{
13+
return str($value)
14+
->lower()
15+
->explode(' ')
16+
->map(fn ($word) => Str::singular($word))
17+
->join(' ');
18+
}
19+
1120
public function handle(DocumentFragment $fragment, $entry): void
1221
{
22+
$fragment->additionalContextData[] = $this->normalizeConent($entry->title);
23+
1324
// Add some extra details to "additional_context"
1425
if (Str::containsAll($fragment->content, ['clear', 'cache'])) {
1526
$fragment->additionalContextData[] = 'delete cache';

app/Search/Listeners/SearchEntriesCreatedListener.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ public function handle(SearchEntriesCreated $event): void
8888

8989
$data['url'] = $data['search_url'];
9090

91+
// Clear this out to prevent "too much" from a specific page dominating the results.
92+
if (! $data['is_root']) {
93+
$data['origin_title'] = null;
94+
}
95+
9196
$section->searchEntry->data($data);
9297
}
9398
}

config/statamic/search.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
'title',
3333
'search_title',
3434
'content',
35+
'origin_title',
3536
'search_content',
3637
'additional_context',
3738
'hierarchy_lvl0',
@@ -45,15 +46,16 @@
4546
'proximity',
4647
'attribute',
4748
'exactness',
49+
'origin_title:desc',
4850
'hierarchy_lvl0:asc',
4951
],
5052
'searchableAttributes' => [
53+
'additional_context',
54+
'hierarchy_lvl0',
5155
'title',
56+
'origin_title',
5257
'search_title',
53-
'content',
5458
'search_content',
55-
'additional_context',
56-
'hierarchy_lvl0',
5759
'hierarchy_lvl1',
5860
'url',
5961
],

resources/views/tabs.antlers.html

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
<div x-data="{ tab: '{{ active }}' }" x-cloak class="mt-2">
22
<div class="relative">
3-
{{#
4-
Don't add tab names to search results. They just clutter it up.
5-
Note: this only works when using the `/documentation-search` views.
6-
#}}
7-
{{ unless is_rendering_search }}
8-
<div class="flex space-x bg-[#292D3E] rounded-t-lg inline-flex">
3+
<div class="flex space-x bg-[#292D3E] rounded-t-lg inline-flex" data-indexer="ignore">
94
{{ foreach:tabs }}
105
<button type="button" class="text-sm bg-black text-gray-dark hover:text-gray-light pt-1.5 pb-1 px-3 rounded-t-md" x-on:click="tab = '{{ key }}'" :class="{ 'bg-[#292D3E] text-gray-light': tab === '{{ key }}' }">{{ value }}</button>
116
{{ /foreach:tabs }}
127
</div>
13-
{{ /unless }}
148
{{ foreach:samples }}
159
<div class="tab-content" x-show="tab === '{{ key }}'">{{ value }}</div>
1610
{{ /foreach:samples }}

0 commit comments

Comments
 (0)