From 0521ea10d66e1b6f0f90b13450361ada446717a9 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Thu, 15 Sep 2022 13:44:00 +0300 Subject: [PATCH] Put image score breakdown under `additional' field in search response - Update web, emacs interfaces to consume the scores from new schema --- src/interface/emacs/khoj.el | 4 ++-- src/interface/web/index.html | 2 +- src/search_type/image_search.py | 17 +++++++++++------ 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/interface/emacs/khoj.el b/src/interface/emacs/khoj.el index c05f98c6..e5b05605 100644 --- a/src/interface/emacs/khoj.el +++ b/src/interface/emacs/khoj.el @@ -187,8 +187,8 @@ Use `which-key` if available, else display simple message in echo area" (lambda (args) (format "\n\n

Score: %s Meta: %s Image: %s

\n\n\n\n" (cdr (assoc 'score args)) - (cdr (assoc 'metadata_score args)) - (cdr (assoc 'image_score args)) + (cdr (assoc 'metadata_score (assoc 'additional args))) + (cdr (assoc 'image_score (assoc 'additional args))) khoj-server-url (cdr (assoc 'entry args)) khoj-server-url diff --git a/src/interface/web/index.html b/src/interface/web/index.html index 5dc76b87..3d940ee3 100644 --- a/src/interface/web/index.html +++ b/src/interface/web/index.html @@ -16,7 +16,7 @@ return ` ` } diff --git a/src/search_type/image_search.py b/src/search_type/image_search.py index a86cc42c..d19a063a 100644 --- a/src/search_type/image_search.py +++ b/src/search_type/image_search.py @@ -220,12 +220,17 @@ def collate_results(hits, image_names, output_directory, image_files_url, count= shutil.copy(source_path, target_path) # Add the image metadata to the results - results += [{ - "entry": f'{image_files_url}/{target_image_name}', - "score": f"{hit['score']:.9f}", - "image_score": f"{hit['image_score']:.9f}", - "metadata_score": f"{hit['metadata_score']:.9f}", - }] + results += [ + { + "entry": f'{image_files_url}/{target_image_name}', + "score": f"{hit['score']:.9f}", + "additional": + { + "image_score": f"{hit['image_score']:.9f}", + "metadata_score": f"{hit['metadata_score']:.9f}", + } + } + ] return results