mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-07 21:29:13 +00:00
Put each result under org heading when query for "all" content type in khoj.el
- Add "all" as default content type when no content type retrieved from server
This commit is contained in:
@@ -598,9 +598,19 @@ CONFIG is json obtained from Khoj config API."
|
|||||||
"Convert JSON-RESPONSE, QUERY from API to text entries."
|
"Convert JSON-RESPONSE, QUERY from API to text entries."
|
||||||
(thread-last json-response
|
(thread-last json-response
|
||||||
;; extract and render entries from API response
|
;; extract and render entries from API response
|
||||||
(mapcar (lambda (args) (format "%s\n\n" (cdr (assoc 'entry args)))))
|
(mapcar (lambda (json-response-item)
|
||||||
|
(thread-last
|
||||||
|
;; Extract pdf entry from each item in json response
|
||||||
|
(cdr (assoc 'entry json-response-item))
|
||||||
|
(format "%s\n\n")
|
||||||
|
;; Standardize results to 2nd level heading for consistent rendering
|
||||||
|
(replace-regexp-in-string "^\*+" "")
|
||||||
|
;; Standardize results to 2nd level heading for consistent rendering
|
||||||
|
(replace-regexp-in-string "^\#+" "")
|
||||||
|
;; Format entries as org entry string
|
||||||
|
(format "** %s"))))
|
||||||
;; Set query as heading in rendered results buffer
|
;; Set query as heading in rendered results buffer
|
||||||
(format "# Query: %s\n\n%s\n" query)
|
(format "* %s\n%s\n" query)
|
||||||
;; remove leading (, ) or SPC from extracted entries string
|
;; remove leading (, ) or SPC from extracted entries string
|
||||||
(replace-regexp-in-string "^[\(\) ]" "")
|
(replace-regexp-in-string "^[\(\) ]" "")
|
||||||
;; remove trailing (, ) or SPC from extracted entries string
|
;; remove trailing (, ) or SPC from extracted entries string
|
||||||
@@ -651,9 +661,7 @@ CONFIG is json obtained from Khoj config API."
|
|||||||
Use QUERY, CONTENT-TYPE and (optional) RERANK as query params"
|
Use QUERY, CONTENT-TYPE and (optional) RERANK as query params"
|
||||||
(let ((rerank (or rerank "false"))
|
(let ((rerank (or rerank "false"))
|
||||||
(encoded-query (url-hexify-string query)))
|
(encoded-query (url-hexify-string query)))
|
||||||
(if content-type
|
(format "%s/api/search?q=%s&t=%s&r=%s&n=%s&client=emacs" khoj-server-url encoded-query content-type rerank khoj-results-count)))
|
||||||
(format "%s/api/search?q=%s&r=%s&n=%s&client=emacs" khoj-server-url encoded-query rerank khoj-results-count)
|
|
||||||
(format "%s/api/search?q=%s&t=%s&r=%s&n=%s&client=emacs&t=%s" khoj-server-url content-type encoded-query rerank khoj-results-count))))
|
|
||||||
|
|
||||||
(defun khoj--query-search-api-and-render-results (query-url content-type query buffer-name)
|
(defun khoj--query-search-api-and-render-results (query-url content-type query buffer-name)
|
||||||
"Query Khoj Search with QUERY-URL.
|
"Query Khoj Search with QUERY-URL.
|
||||||
@@ -676,7 +684,8 @@ Render results in BUFFER-NAME using QUERY, CONTENT-TYPE."
|
|||||||
((equal content-type "ledger") (khoj--extract-entries-as-ledger json-response query))
|
((equal content-type "ledger") (khoj--extract-entries-as-ledger json-response query))
|
||||||
((equal content-type "image") (khoj--extract-entries-as-images json-response query))
|
((equal content-type "image") (khoj--extract-entries-as-images json-response query))
|
||||||
(t (khoj--extract-entries json-response query))))
|
(t (khoj--extract-entries json-response query))))
|
||||||
(cond ((or (equal content-type "pdf")
|
(cond ((or (equal content-type "all")
|
||||||
|
(equal content-type "pdf")
|
||||||
(equal content-type "org"))
|
(equal content-type "org"))
|
||||||
(progn (visual-line-mode)
|
(progn (visual-line-mode)
|
||||||
(org-mode)
|
(org-mode)
|
||||||
@@ -1005,7 +1014,7 @@ Paragraph only starts at first text after blank line."
|
|||||||
;; set content type to: last used > based on current buffer > default type
|
;; set content type to: last used > based on current buffer > default type
|
||||||
:init-value (lambda (obj) (oset obj value (format "--content-type=%s" (or khoj--content-type (khoj--buffer-name-to-content-type (buffer-name))))))
|
:init-value (lambda (obj) (oset obj value (format "--content-type=%s" (or khoj--content-type (khoj--buffer-name-to-content-type (buffer-name))))))
|
||||||
;; dynamically set choices to content types enabled on khoj backend
|
;; dynamically set choices to content types enabled on khoj backend
|
||||||
:choices (or (ignore-errors (mapcar #'symbol-name (khoj--get-enabled-content-types))) '("org" "markdown" "pdf" "ledger" "music" "image")))
|
:choices (or (ignore-errors (mapcar #'symbol-name (khoj--get-enabled-content-types))) '("all" "org" "markdown" "pdf" "ledger" "music" "image")))
|
||||||
|
|
||||||
(transient-define-suffix khoj--search-command (&optional args)
|
(transient-define-suffix khoj--search-command (&optional args)
|
||||||
(interactive (list (transient-args transient-current-command)))
|
(interactive (list (transient-args transient-current-command)))
|
||||||
|
|||||||
Reference in New Issue
Block a user