|
8 | 8 |
|
9 | 9 | from django.conf import settings
|
10 | 10 | from django.contrib.sites.models import Site
|
| 11 | +from django.db import connection |
11 | 12 | from django.template import Context, Template
|
12 | 13 | from django.template.loader import render_to_string
|
13 | 14 | from django.test import RequestFactory, TestCase
|
|
16 | 17 | from djangoproject.urls import www as www_urls
|
17 | 18 | from releases.models import Release
|
18 | 19 |
|
19 |
| -from .models import Document, DocumentRelease |
| 20 | +from .models import DOCUMENT_SEARCH_VECTOR, Document, DocumentRelease |
20 | 21 | from .sitemaps import DocsSitemap
|
21 | 22 | from .templatetags.docs import get_all_doc_versions
|
22 | 23 | from .utils import get_doc_path
|
@@ -616,6 +617,31 @@ def test_search_update(self):
|
616 | 617 | self.assertEqual(Document.objects.search_update(), 6)
|
617 | 618 | self.assertEqual(Document.objects.exclude(search=None).count(), 6)
|
618 | 619 |
|
| 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 | + |
619 | 645 |
|
620 | 646 | class TemplateTestCase(TestCase):
|
621 | 647 | def _assertOGTitleEqual(self, doc, expected):
|
|
0 commit comments