search: fix view when indexed cell has no page (#51251)
This commit is contained in:
parent
72f2a0efb0
commit
69d97b1c08
|
@ -143,7 +143,7 @@ def search_site(request, query, pages=None, with_description=None):
|
|||
'text': hit.title,
|
||||
'rank': getattr(hit, 'rank', None),
|
||||
'url': hit.url,
|
||||
'description': hit.page.description if with_description is True else '',
|
||||
'description': hit.page.description if (hit.page and with_description is True) else '',
|
||||
}
|
||||
)
|
||||
seen[hit.url] = True
|
||||
|
|
|
@ -5,6 +5,7 @@ import mock
|
|||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import AnonymousUser, User, Group
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.db import connection
|
||||
from django.test import override_settings
|
||||
from django.test.client import RequestFactory
|
||||
|
@ -401,13 +402,20 @@ def test_search_api(app):
|
|||
result = result.replace('\n', '')
|
||||
assert '<li><a href="/second-page/">second page</a></li>' in result
|
||||
|
||||
# indexed cell without page
|
||||
cell_type = ContentType.objects.get_for_model(cell)
|
||||
IndexedCell.objects.create(
|
||||
title='other', cell_type=cell_type, cell_pk=cell.pk, public_access=True, url='fake'
|
||||
)
|
||||
# enable description
|
||||
cell._search_services['options'] = {'_text': {'with_description': True}}
|
||||
cell.save()
|
||||
resp = app.get('/ajax/search/%s/_text/?q=other' % cell.id, status=200)
|
||||
assert resp.text.count('<li') == 1
|
||||
assert resp.text.count('<li') == 2
|
||||
result = resp.text
|
||||
result = result.replace(' ', '')
|
||||
result = result.replace('\n', '')
|
||||
assert '<li><a href="fake">other</a></li>' in result
|
||||
assert '<li><a href="/second-page/">second page</a><div>Foo Bar Description</div></li>' in result
|
||||
|
||||
resp = app.get('/ajax/search/%s/_text/?q=baz' % cell.id, status=200)
|
||||
|
|
Loading…
Reference in New Issue