Просмотр исходного кода

fix: can't find default property values in search

Fixes LOG-2921
Tienson Qin 2 лет назад
Родитель
Сommit
a1093171df

+ 2 - 1
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
   []

+ 53 - 7
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)

+ 1 - 1
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])