search: do not consider page with sub_slug (#40108)

This commit is contained in:
Thomas NOËL 2020-02-25 17:12:03 +01:00 committed by Thomas NOËL
parent 0215e2424b
commit 3662751240
2 changed files with 19 additions and 1 deletions

View File

@ -44,7 +44,7 @@ def index_site():
IndexedCell.objects.all().delete()
external_urls = {}
for klass in CellBase.get_cell_classes():
for cell in klass.objects.filter(page__snapshot__isnull=True).exclude(placeholder__startswith='_'):
for cell in klass.objects.filter(page__snapshot__isnull=True, page__sub_slug='').exclude(placeholder__startswith='_'):
cell_type = ContentType.objects.get_for_model(cell)
indexed_cell = IndexedCell(cell_type=cell_type, cell_pk=cell.id)
try:

View File

@ -510,3 +510,21 @@ def test_restricted_search(app):
assert len(hits) == 0
hits = search_site(request, 'barfoo')
assert len(hits) == 1
def test_no_sub_slug_search(app):
page = Page(title='example page', slug='example-page')
page.save()
TextCell(page=page, text='<p>foobar</p>', order=0, public=True).save()
page = Page(title='example page with sub_slug', slug='sub-slugged-page',
sub_slug='(?P<foo>\d+)')
page.save()
TextCell(page=page, text='<p>barfoo</p>', order=0, public=True).save()
request = RequestFactory().get('/')
request.user = AnonymousUser()
index_site()
hits = search_site(request, 'foobar')
assert len(hits) == 1
hits = search_site(request, 'barfoo')
assert len(hits) == 0