Skip to content

Commit 40a3e19

Browse files
committed
[bug 904443] Shorten contributor forum excerpts
The post_content is an array of strings--one for each post in the thread. This changes excerpting so that we only use the first post in the search results summary.
1 parent c88f137 commit 40a3e19

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

kitsune/search/views.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ def search(request, template=None):
420420
'num_votes_past_week': doc['question_num_votes_past_week']}
421421

422422
else:
423-
summary = _build_es_excerpt(doc)
423+
summary = _build_es_excerpt(doc, first_only=True)
424424
result = {
425425
'title': doc['post_title'],
426426
'type': 'thread'}
@@ -563,15 +563,23 @@ def _ternary_filter(ternary_value):
563563
return ternary_value == constants.TERNARY_YES
564564

565565

566-
def _build_es_excerpt(result):
566+
def _build_es_excerpt(result, first_only=False):
567567
"""Return concatenated search excerpts.
568568
569569
:arg result: The result object from the queryset results
570+
:arg first_only: True if we should show only the first bit, False
571+
if we should show all bits
570572
571573
"""
572-
excerpt = EXCERPT_JOINER.join(
573-
[m.strip() for m in
574-
chain(*result._highlight.values()) if m])
574+
bits = [m.strip() for m in
575+
chain(*result._highlight.values()) if m]
576+
577+
if first_only and bits:
578+
excerpt = bits[0]
579+
else:
580+
excerpt = EXCERPT_JOINER.join(
581+
[m.strip() for m in
582+
chain(*result._highlight.values()) if m])
575583

576584
return jinja2.Markup(clean_excerpt(excerpt))
577585

0 commit comments

Comments
 (0)