Skip to content

Commit e6987d1

Browse files
committed
Fixed #1629 -- Fixed search highlighting not working on stemmed words
1 parent 2b3b8c3 commit e6987d1

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

docs/models.py

+2
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,14 @@ def search(self, query_text, release):
272272
search_query,
273273
start_sel="<mark>",
274274
stop_sel="</mark>",
275+
config=models.F("config"),
275276
),
276277
highlight=SearchHeadline(
277278
KeyTextTransform("body", "metadata"),
278279
search_query,
279280
start_sel="<mark>",
280281
stop_sel="</mark>",
282+
config=models.F("config"),
281283
),
282284
breadcrumbs=models.F("metadata__breadcrumbs"),
283285
)

docs/tests.py

+27-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from django.conf import settings
1010
from django.contrib.sites.models import Site
11+
from django.db import connection
1112
from django.template import Context, Template
1213
from django.template.loader import render_to_string
1314
from django.test import RequestFactory, TestCase
@@ -16,7 +17,7 @@
1617
from djangoproject.urls import www as www_urls
1718
from releases.models import Release
1819

19-
from .models import Document, DocumentRelease
20+
from .models import DOCUMENT_SEARCH_VECTOR, Document, DocumentRelease
2021
from .sitemaps import DocsSitemap
2122
from .templatetags.docs import get_all_doc_versions
2223
from .utils import get_doc_path
@@ -616,6 +617,31 @@ def test_search_update(self):
616617
self.assertEqual(Document.objects.search_update(), 6)
617618
self.assertEqual(Document.objects.exclude(search=None).count(), 6)
618619

620+
def test_search_highlight_stemmed(self):
621+
# The issue only manifests itself when the defaut search config is not english
622+
with connection.cursor() as cursor:
623+
cursor.execute("SET default_text_search_config TO 'simple'", [])
624+
625+
doc = self.release.documents.create(
626+
config="english",
627+
path="/",
628+
title="triaging tickets",
629+
metadata={"body": "text containing the word triaging", "breadcrumbs": []},
630+
)
631+
doc.search = DOCUMENT_SEARCH_VECTOR
632+
doc.save(update_fields=["search"])
633+
634+
self.assertQuerySetEqual(
635+
Document.objects.search("triaging", self.release),
636+
[
637+
(
638+
"<mark>triaging</mark> tickets",
639+
"text containing the word <mark>triaging</mark>",
640+
)
641+
],
642+
transform=attrgetter("headline", "highlight"),
643+
)
644+
619645

620646
class TemplateTestCase(TestCase):
621647
def _assertOGTitleEqual(self, doc, expected):

0 commit comments

Comments
 (0)