From 06b0c720d6201490be8ff50ca443123ce33bdd88 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Sat, 16 Jul 2022 19:31:49 +0400 Subject: [PATCH] Improve Rendering of Image Search Results in Emacs - Use shr to render image response from html in result buffer Earlier was using org-mode. But rendering HTML with shr seems cleaner - Use Headings to Add highlights - Use Random to Force fetch of Image. Similar to what was done for Web interface - Remove trailing elisp brackets from response - Show query match scores by image model for each image in results --- src/interface/emacs/semantic-search.el | 35 +++++++++++++++++--------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/interface/emacs/semantic-search.el b/src/interface/emacs/semantic-search.el index 765ac923..4dad77b5 100644 --- a/src/interface/emacs/semantic-search.el +++ b/src/interface/emacs/semantic-search.el @@ -61,13 +61,25 @@ "Convert json response from API to org-mode entries with images" ;; remove leading (, ) or SPC from extracted entries string (replace-regexp-in-string - "^[\(\) ]" "" - ;; extract entries from response as single string and convert to entries - (format "* %s \n%s" - query - (mapcar - (lambda (args) (format "\n** \n [[%s%s]]" semantic-search--server-url (cdr (assoc 'entry args)))) - json-response)))) + "[\(\) ]$" "" + ;; remove leading (, ) or SPC from extracted entries string + (replace-regexp-in-string + "^[\(\) ]" "" + ;; extract entries from response as single string and convert to entries + (format "\n\n

%s

%s\n\n\n" + query + (mapcar + (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)) + semantic-search--server-url + (cdr (assoc 'entry args)) + semantic-search--server-url + (cdr (assoc 'entry args)) + (random 10000))) + json-response))))) (defun semantic-search--extract-entries-as-ledger (json-response query) "Convert json response from API to ledger entries" @@ -118,15 +130,14 @@ (cond ((or (equal search-type "notes") (equal search-type "music")) (semantic-search--extract-entries-as-org json-response query)) ((equal search-type "ledger") (semantic-search--extract-entries-as-ledger json-response query)) ((equal search-type "image") (semantic-search--extract-entries-as-images json-response query)) - (t (format "%s" json-response))))) + (t (format "%s" json-response)))) (cond ((equal search-type "notes") (org-mode)) ((equal search-type "ledger") (beancount-mode)) ((equal search-type "music") (progn (org-mode) (org-music-mode))) - ((equal search-type "image") (progn (org-mode) - (setq org-image-actual-width semantic-search--image-width) - (org-display-inline-images))) - (t (fundamental-mode))) + ((equal search-type "image") (progn (shr-render-region (point-min) (point-max)) + (goto-char (point-min)))) + (t (fundamental-mode)))) (read-only-mode t)) (switch-to-buffer buff)))