Skip to content

Commit

Permalink
Merge pull request #21 from macopedia/highlighting
Browse files Browse the repository at this point in the history
Highlighting
  • Loading branch information
tmotyl authored Jun 18, 2021
2 parents 9d9963d + 6f9486f commit 8c4f42d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/Repository/ElasticRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,15 @@ public function findByQuery(SearchDemand $searchDemand): array
],
],
],
'highlight' => [
'fields' => [
'snippet_content' => [
'fragment_size' => 400,
'number_of_fragments' => 1
]
],
'encoder' => 'html'
]
];
$filters = $searchDemand->getFilters();
if (!empty($filters)) {
Expand Down
10 changes: 9 additions & 1 deletion templates/search/search.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
display: block;
}
}
.summary em {
font-style: normal;
font-weight: 600;
}
</style>
{% endblock %}

Expand All @@ -78,7 +82,11 @@
<span class="badge badge-primary text-decoration-none">{{ version }}</span>
{% endfor %}
</h4>
<p class="summary">{{ hit.data.snippet_content|slice(0, 400) }}...</p>
{% if hit.highlights.snippet_content[0] %}
<p class="summary">{{ hit.highlights.snippet_content[0] | raw }}...</p>
{% else %}
<p class="summary">{{ hit.data.snippet_content|slice(0, 400) }}...</p>
{% endif %}
</a>
{% endfor %}
</ul>
Expand Down

0 comments on commit 8c4f42d

Please sign in to comment.