mirror of
https://github.com/logseq/logseq.git
synced 2026-05-04 19:06:21 +00:00
fix: can't find default property values in search
Fixes LOG-2921
This commit is contained in:
@@ -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,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])
|
||||
|
||||
Reference in New Issue
Block a user