enhance: search tweaks

pull/1658/head
Tienson Qin 2021-04-12 21:30:26 +08:00
parent 422fd8353b
commit 73c9f05139
6 changed files with 13 additions and 8 deletions

View File

@ -106,7 +106,6 @@
true)
(defmethod handle :search-blocks [window [_ repo q limit]]
(prn {:limit limti})
(search/search-blocks repo q limit))
(defmethod handle :rebuild-blocks-indice [window [_ repo data]]

View File

@ -130,10 +130,10 @@
;; (js->clj (.all ^object stmt q) :keywordize-keys true))))
(defn search-blocks
[repo q]
[repo q limit]
(when-let [database (get-db repo)]
(when-not (string/blank? q)
(let [limit (or limit 100)
(let [limit (or limit 20)
stmt (prepare database
"select id, uuid, content from blocks where content like ? limit ?")]
(js->clj (.all ^object stmt (str "%" q "%") limit) :keywordize-keys true)))))

View File

@ -303,7 +303,10 @@
(state/set-q! value)
(reset! search-timeout
(js/setTimeout
#(search-handler/search (state/get-current-repo) value opts)
(fn []
(if (= :page search-mode)
(search-handler/search (state/get-current-repo) value opts)
(search-handler/search (state/get-current-repo) value)))
timeout))))))}]
(when-not (string/blank? search-q)
(ui/css-transition
@ -319,7 +322,8 @@
(rum/with-context [[t] i18n/*tongue-context*]
[:div#search.flex-1.flex
[:div.inner
[:h1.title "Search result for " [:i search-q]]
[:h1.title (t :search/result-for) [:i search-q]]
[:p.font-medium.tx-sm (str (count (:blocks search-result)) " " (t :search/items))]
[:div#search-wrapper.relative.w-full.text-gray-400.focus-within:text-gray-600
(when-not (string/blank? search-q)
(search-auto-complete search-result search-q true))]]])))

View File

@ -155,6 +155,7 @@ title: How to take dummy notes?
:general "General"
:more "More"
:search/result-for "Search result for "
:search/items "items"
:help/toggle "Toggle help"
:help/git-commit-message "Git commit message"
:help/full-text-search "Full Text Search"
@ -887,6 +888,7 @@ title: How to take dummy notes?
:general "常规​​​​​"
:more "更多"
:search/result-for "更多搜索结果 "
:search/items "条目"
:help/toggle "显示/关闭帮助"
:help/git-commit-message "提交消息"
:help/full-text-search "全文搜索"

View File

@ -11,13 +11,12 @@
(defn search
([repo q]
(search repo q nil))
(search repo q {:limit 20}))
([repo q {:keys [page-db-id limit more?]
:or {page-db-id nil
limit 20}
:as opts}]
(let [limit (:limit opts)
page-db-id (if (string? page-db-id)
(let [page-db-id (if (string? page-db-id)
(:db/id (db/entity repo [:page/name (string/lower-case page-db-id)]))
page-db-id)]
(p/let [blocks (search/block-search repo q opts)]

View File

@ -10,6 +10,7 @@
(defrecord Node [repo]
protocol/Engine
(query [this q {:keys [limit]}]
(prn {:limit limit})
(p/let [result (ipc/ipc "search-blocks" repo q limit)
result (bean/->clj result)]
(map (fn [{:keys [content id uuid]}]