fix: can't find default property values in search

Fixes LOG-2921
This commit is contained in:
Tienson Qin
2023-11-21 12:49:29 +08:00
parent 89284f07fd
commit a1093171df
3 changed files with 56 additions and 9 deletions

View File

@@ -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)

View File

@@ -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])