Search by image at path only if query of form "file:/path/to/image"

Previously no query syntax helpers, like the "file:" prefix, were used
before checking if query contains file path.

This made query to image search brittle to misinterpretation and
pointless checking

Add test to verify search by image at file works as expected
This commit is contained in:
Debanjum Singh Solanky
2023-01-21 14:06:56 -03:00
parent 655ef11653
commit 3d9ed91e42
2 changed files with 44 additions and 4 deletions

View File

@@ -136,12 +136,12 @@ def extract_metadata(image_name):
def query(raw_query, count, model: ImageSearchModel):
# Set query to image content if query is a filepath
if pathlib.Path(raw_query).is_file():
query_imagepath = resolve_absolute_path(pathlib.Path(raw_query), strict=True)
# Set query to image content if query is of form file:/path/to/file.png
if raw_query.startswith("file:") and pathlib.Path(raw_query[5:]).is_file():
query_imagepath = resolve_absolute_path(pathlib.Path(raw_query[5:]), strict=True)
query = copy.deepcopy(Image.open(query_imagepath))
query.thumbnail((640, query.height)) # scale down image for faster processing
logger.info(f"Find Images similar to Image at {query_imagepath}")
logger.info(f"Find Images by Image: {query_imagepath}")
else:
query = raw_query
logger.info(f"Find Images by Text: {query}")