Skip to content

Commit 8c4f42d

Browse files
authored
Merge pull request #21 from macopedia/highlighting
Highlighting
2 parents 9d9963d + 6f9486f commit 8c4f42d

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/Repository/ElasticRepository.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,15 @@ public function findByQuery(SearchDemand $searchDemand): array
194194
],
195195
],
196196
],
197+
'highlight' => [
198+
'fields' => [
199+
'snippet_content' => [
200+
'fragment_size' => 400,
201+
'number_of_fragments' => 1
202+
]
203+
],
204+
'encoder' => 'html'
205+
]
197206
];
198207
$filters = $searchDemand->getFilters();
199208
if (!empty($filters)) {

templates/search/search.html.twig

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@
5656
display: block;
5757
}
5858
}
59+
.summary em {
60+
font-style: normal;
61+
font-weight: 600;
62+
}
5963
</style>
6064
{% endblock %}
6165

@@ -78,7 +82,11 @@
7882
<span class="badge badge-primary text-decoration-none">{{ version }}</span>
7983
{% endfor %}
8084
</h4>
81-
<p class="summary">{{ hit.data.snippet_content|slice(0, 400) }}...</p>
85+
{% if hit.highlights.snippet_content[0] %}
86+
<p class="summary">{{ hit.highlights.snippet_content[0] | raw }}...</p>
87+
{% else %}
88+
<p class="summary">{{ hit.data.snippet_content|slice(0, 400) }}...</p>
89+
{% endif %}
8290
</a>
8391
{% endfor %}
8492
</ul>

0 commit comments

Comments
 (0)