mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-08 05:39:13 +00:00
Rerank results on normal minibuffer exit
In current state: - Rerank results: - If user idles while entering query OR - exits normally - Do not rerank results: - If user exits abnormally, e.g via C-g from query
This commit is contained in:
@@ -186,13 +186,18 @@
|
|||||||
;; Query khoj API only when user in khoj minibuffer.
|
;; Query khoj API only when user in khoj minibuffer.
|
||||||
;; Prevents querying during recursive edits or with contents of other buffers user may jump to
|
;; Prevents querying during recursive edits or with contents of other buffers user may jump to
|
||||||
(when (and (active-minibuffer-window) (equal (current-buffer) khoj--minibuffer-window))
|
(when (and (active-minibuffer-window) (equal (current-buffer) khoj--minibuffer-window))
|
||||||
(khoj--query-api-and-render-results
|
(progn
|
||||||
query
|
(when rerank
|
||||||
search-type
|
(message "[Khoj]: Rerank Results"))
|
||||||
query-url
|
(khoj--query-api-and-render-results
|
||||||
buffer-name))))
|
query
|
||||||
|
search-type
|
||||||
|
query-url
|
||||||
|
buffer-name)))))
|
||||||
|
|
||||||
(defun khoj--teardown-incremental-search ()
|
(defun khoj--teardown-incremental-search ()
|
||||||
|
;; remove advice to rerank results on normal exit from minibuffer
|
||||||
|
(advice-remove 'exit-minibuffer #'khoj--minibuffer-exit-advice)
|
||||||
;; unset khoj minibuffer window
|
;; unset khoj minibuffer window
|
||||||
(setq khoj--minibuffer-window nil)
|
(setq khoj--minibuffer-window nil)
|
||||||
;; cancel rerank timer
|
;; cancel rerank timer
|
||||||
@@ -202,6 +207,8 @@
|
|||||||
(remove-hook 'post-command-hook #'khoj--incremental-search)
|
(remove-hook 'post-command-hook #'khoj--incremental-search)
|
||||||
(remove-hook 'minibuffer-exit-hook #'khoj--teardown-incremental-search))
|
(remove-hook 'minibuffer-exit-hook #'khoj--teardown-incremental-search))
|
||||||
|
|
||||||
|
(defun khoj--minibuffer-exit-advice (&rest _args)
|
||||||
|
(khoj--incremental-search t))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun khoj ()
|
(defun khoj ()
|
||||||
@@ -221,6 +228,8 @@
|
|||||||
;; set current (mini-)buffer entered as khoj minibuffer
|
;; set current (mini-)buffer entered as khoj minibuffer
|
||||||
;; used to query khoj API only when user in khoj minibuffer
|
;; used to query khoj API only when user in khoj minibuffer
|
||||||
(setq khoj--minibuffer-window (current-buffer))
|
(setq khoj--minibuffer-window (current-buffer))
|
||||||
|
;; rerank results on normal exit from minibuffer
|
||||||
|
(advice-add 'exit-minibuffer :before #'khoj--minibuffer-exit-advice)
|
||||||
(add-hook 'post-command-hook #'khoj--incremental-search) ; do khoj incremental search after every user action
|
(add-hook 'post-command-hook #'khoj--incremental-search) ; do khoj incremental search after every user action
|
||||||
(add-hook 'minibuffer-exit-hook #'khoj--teardown-incremental-search)) ; teardown khoj incremental search on minibuffer exit
|
(add-hook 'minibuffer-exit-hook #'khoj--teardown-incremental-search)) ; teardown khoj incremental search on minibuffer exit
|
||||||
(read-string khoj--query-prompt))))
|
(read-string khoj--query-prompt))))
|
||||||
|
|||||||
Reference in New Issue
Block a user