From 2a16cdd98ed1f076f0bc036417f8b7a0c2e6c10c Mon Sep 17 00:00:00 2001 From: Roland Date: Mon, 24 Oct 2022 09:06:29 -0600 Subject: [PATCH] Hiding associated files from search results. --- wrolpi/files/lib.py | 6 +++--- wrolpi/files/test/test_api.py | 2 -- wrolpi/files/test/test_lib.py | 7 +++---- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/wrolpi/files/lib.py b/wrolpi/files/lib.py index cc46ecde..f5e2f9e1 100644 --- a/wrolpi/files/lib.py +++ b/wrolpi/files/lib.py @@ -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}/%' diff --git a/wrolpi/files/test/test_api.py b/wrolpi/files/test/test_api.py index 78f91f31..68c71aeb 100644 --- a/wrolpi/files/test/test_api.py +++ b/wrolpi/files/test/test_api.py @@ -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'}, ] ) diff --git a/wrolpi/files/test/test_lib.py b/wrolpi/files/test/test_lib.py index a008514e..27ecdd19 100644 --- a/wrolpi/files/test/test_lib.py +++ b/wrolpi/files/test/test_lib.py @@ -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)