From a1093171df4ea38350c92a0903781ed7dba00a71 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Tue, 21 Nov 2023 12:49:29 +0800 Subject: [PATCH] fix: can't find default property values in search Fixes LOG-2921 --- src/main/frontend/db/model.cljs | 3 +- src/main/frontend/search/db.cljs | 60 +++++++++++++++++++++++--- src/main/frontend/search/protocol.cljs | 2 +- 3 files changed, 56 insertions(+), 9 deletions(-) diff --git a/src/main/frontend/db/model.cljs b/src/main/frontend/db/model.cljs index 0350be5197..6edc2e1a2b 100644 --- a/src/main/frontend/db/model.cljs +++ b/src/main/frontend/db/model.cljs @@ -1339,7 +1339,8 @@ independent of format as format specific heading characters are stripped" :block/uuid id :block/page (:db/id (:block/page e)) :block/content (:block/content e) - :block/format (:block/format e)}))) + :block/format (:block/format e) + :block/properties (:block/properties e)}))) (defn get-all-block-contents [] diff --git a/src/main/frontend/search/db.cljs b/src/main/frontend/search/db.cljs index a6c0426d32..d1a5afc7c5 100644 --- a/src/main/frontend/search/db.cljs +++ b/src/main/frontend/search/db.cljs @@ -4,6 +4,7 @@ [frontend.db :as db] [frontend.db.model :as model] [frontend.state :as state] + [frontend.config :as config] [frontend.util :as util] ["fuse.js" :as fuse])) @@ -20,15 +21,60 @@ (some-> content (util/search-normalize (state/enable-search-remove-accents?)))) +(defn- get-db-properties-str + [properties] + (->> properties + (map + (fn [[k v]] + (let [value (if (uuid? v) + (let [e (db/entity [:block/uuid v]) + value (or + ;; closed value + (when-let [v' (get-in e [:block/schema :value])] + (if (uuid? v') + (let [b (db/entity [:block/uuid v'])] + (or + ;; page + (:block/original-name b) + (:block/content b))) + v')) + ;; page + (:block/original-name e) + ;; block generated by template + (and + (get-in e [:block/metadata :created-from-template]) + (:block/content e)) + ;; first child + (let [parent-id (:db/id e)] + (:block/content (model/get-by-parent-&-left (db/get-db) parent-id parent-id))))] + value) + v)] + (when (and (not (string/blank? value)) + (not (uuid? value))) + (str (:block/original-name (db/entity [:block/uuid k])) + ": " + value))))) + (remove nil?) + (string/join "\n"))) + (defn block->index "Convert a block to the index for searching" - [{:block/keys [uuid page content] :as block}] - (when-not (> (count content) (max-len)) - (when-not (string/blank? content) - {:id (:db/id block) - :uuid (str uuid) - :page page - :content (sanitize content)}))) + [{:block/keys [uuid page content properties] :as block}] + (let [repo (state/get-current-repo)] + (when-not (> (count content) (max-len)) + (when-not (and (string/blank? content) + (empty? properties)) + (let [m {:id (:db/id block) + :uuid (str uuid) + :page page + :content (sanitize content)} + m' (cond-> m + (and (config/db-based-graph? repo) (seq properties)) + (update :content + (fn [content] + (str content "\n" + (get-db-properties-str properties)))))] + m'))))) (defn page->index "Convert a page name to the index for searching (page content level) diff --git a/src/main/frontend/search/protocol.cljs b/src/main/frontend/search/protocol.cljs index 3b3efdcf1a..e5578ff1e3 100644 --- a/src/main/frontend/search/protocol.cljs +++ b/src/main/frontend/search/protocol.cljs @@ -1,7 +1,7 @@ (ns ^:no-doc frontend.search.protocol) (defprotocol Engine - (query [this q option]) + (query [this q option]) (query-page [this q option]) (rebuild-blocks-indice! [this]) ;; TODO: rename to rebuild-indice! (transact-blocks! [this data])