mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-25 01:16:18 -05:00
Testing Archive headline search.
This commit is contained in:
parent
bba6a341b7
commit
f9ad9981db
4 changed files with 33 additions and 8 deletions
|
|
@ -406,7 +406,7 @@ def search_archives(search_str: str, domain: str, limit: int, offset: int, order
|
|||
params.update(params_)
|
||||
joins.append(join_)
|
||||
|
||||
if headline:
|
||||
if search_str and headline:
|
||||
headline = ''',
|
||||
ts_headline(fg.title, websearch_to_tsquery(%(search_str)s)) AS "title_headline",
|
||||
ts_headline(fg.b_text, websearch_to_tsquery(%(search_str)s)) AS "b_headline",
|
||||
|
|
|
|||
|
|
@ -62,6 +62,31 @@ def test_archives_search(test_session, archive_directory, archive_factory, test_
|
|||
assert response.status_code == HTTPStatus.BAD_REQUEST
|
||||
|
||||
|
||||
def test_archives_search_headline(test_session, archive_directory, archive_factory, test_client):
|
||||
"""Headlines can be requested."""
|
||||
archive_factory('example.com', 'https://example.com/one', 'my archive', 'foo bar qux')
|
||||
archive_factory('example.com', 'https://example.com/one', 'other archive', 'foo baz qux qux')
|
||||
archive_factory('example.org', title='archive third', contents='baz qux qux qux')
|
||||
archive_factory('example.org') # has no contents
|
||||
test_session.commit()
|
||||
|
||||
content = dict(search_str='foo')
|
||||
request, response = test_client.post('/api/archive/search', content=json.dumps(content))
|
||||
assert response.status_code == HTTPStatus.OK
|
||||
|
||||
# Headlines are only fetched if requested.
|
||||
assert response.json['file_groups'][0]['d_headline'] is None
|
||||
assert response.json['file_groups'][1]['d_headline'] is None
|
||||
|
||||
content = dict(search_str='foo', headline=True)
|
||||
request, response = test_client.post('/api/archive/search', content=json.dumps(content))
|
||||
assert response.status_code == HTTPStatus.OK
|
||||
|
||||
# Postgresql uses <b>...</b> to highlight matching words.
|
||||
assert response.json['file_groups'][0]['d_headline'] == '<b>foo</b> baz qux qux'
|
||||
assert response.json['file_groups'][1]['d_headline'] == '<b>foo</b> bar qux'
|
||||
|
||||
|
||||
def test_search_offset(test_session, archive_factory, test_client):
|
||||
"""Archive search can be offset."""
|
||||
for i in range(500):
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ def search_videos(
|
|||
params.update(params_)
|
||||
joins.append(join_)
|
||||
|
||||
if headline:
|
||||
if search_str and headline:
|
||||
headline = ''',
|
||||
ts_headline(fg.title, websearch_to_tsquery(%(search_str)s)) AS "title_headline",
|
||||
ts_headline(fg.b_text, websearch_to_tsquery(%(search_str)s)) AS "b_headline",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue