Hiding associated files from search results.

This commit is contained in:
Roland 2022-10-24 09:06:29 -06:00
parent 24df7c464e
commit 2a16cdd98e
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
3 changed files with 6 additions and 9 deletions

View file

@ -290,15 +290,15 @@ def file_search(search_str: str, limit: int, offset: int, mimetype: str = None,
model: Only return files that match this model.
"""
params = dict(offset=offset, limit=limit)
wheres = []
wheres = ['associated = false']
selects = []
order_by = 'associated, 1 ASC'
order_by = '1 ASC'
if search_str:
params['search_str'] = search_str
wheres.append('textsearch @@ websearch_to_tsquery(%(search_str)s)')
selects.append('ts_rank(textsearch, websearch_to_tsquery(%(search_str)s))')
order_by = 'associated, 2 DESC'
order_by = '2 DESC'
if mimetype and len(mimetype.split('/')) == 1:
params['mimetype'] = f'{mimetype}/%'

View file

@ -204,7 +204,5 @@ def test_associated_files(test_session, test_client, make_files_structure):
[
{'path': 'not a video.txt'},
{'path': 'video.mp4'},
{'path': 'video.info.json'},
{'path': 'video.png'},
]
)

View file

@ -281,7 +281,7 @@ async def test_files_indexer(test_session, make_files_structure):
'a zip file.zip',
'images/an image file.jpeg',
'unknown file',
'videos/a video file.info.json',
'videos/a video file.info.json', # This is "associated" and will be hidden.
'videos/a video file.mp4',
]
bzip_path, gzip_path, text_path, zip_path, image_path, unknown_path, info_json_path, video_path \
@ -327,14 +327,13 @@ async def test_files_indexer(test_session, make_files_structure):
# File are indexed by their titles and contents.
files, total = lib.file_search('file', 10, 0)
assert total == len(source_files), 'All files contain "file" in their file name.'
assert total == 7, 'All files contain "file" in their file name. The associated video file is hidden.'
files, total = lib.file_search('image', 10, 0)
assert total == 1 and files[0]['title'] == 'an image file.jpeg', 'The image file title contains "image".'
files, total = lib.file_search('contents', 10, 0)
assert total == 1 and files[0]['title'] == 'a text file.txt', 'The text file contains "contents".'
files, total = lib.file_search('video', 10, 0)
assert total == 2 and {i['title'] for i in files} == {'a video file.info.json', 'a video file.mp4'}, \
'The video files contains "video".'
assert total == 1 and {i['title'] for i in files} == {'a video file.mp4'}, 'The video file contains "video".'
files, total = lib.file_search('yawn', 10, 0)
assert total == 1 and files[0]['title'] == 'a video file.mp4', 'The video file captions contain "yawn".'
files, total = lib.file_search('bunny', 10, 0)