mirror of
https://github.com/logseq/logseq.git
synced 2026-05-29 23:19:38 +00:00
fix: keep canonical page title in search results
This commit is contained in:
@@ -108,8 +108,6 @@ DROP TRIGGER IF EXISTS blocks_au;
|
||||
|
||||
(defn- throw-upsert-blocks-error!
|
||||
[item]
|
||||
(js/console.error "Upsert blocks wrong data: ")
|
||||
(js/console.dir item)
|
||||
(throw (ex-info "Search upsert-blocks wrong data: "
|
||||
(bean/->clj item))))
|
||||
|
||||
@@ -537,6 +535,10 @@ DROP TRIGGER IF EXISTS blocks_au;
|
||||
(string/join " "))
|
||||
title)))
|
||||
|
||||
(defn- block-result-title
|
||||
[block]
|
||||
(db-content/recur-replace-uuid-in-block-title block))
|
||||
|
||||
(defn- matched-alias
|
||||
[q block]
|
||||
(when-not (string/blank? q)
|
||||
@@ -670,9 +672,13 @@ DROP TRIGGER IF EXISTS blocks_au;
|
||||
(let [alias-source (some-> (first (:block/_alias block))
|
||||
(select-keys [:block/uuid :block/title]))
|
||||
alias-match (matched-alias q block)
|
||||
page-or-object-result? (page-or-object? block)
|
||||
result-title (if page-or-object-result? (block-result-title block) title)
|
||||
display-title (if (:enable-snippet? option)
|
||||
(ensure-highlighted-snippet snippet title q)
|
||||
(or snippet title))
|
||||
(ensure-highlighted-snippet snippet result-title q)
|
||||
(if page-or-object-result?
|
||||
result-title
|
||||
(or snippet title)))
|
||||
block-page (or
|
||||
(:block/uuid (:block/page block))
|
||||
(when (and page (common-util/uuid-string? page))
|
||||
|
||||
@@ -618,6 +618,36 @@
|
||||
(is (= "Artificial Intelligence" (:block/title result)))
|
||||
(is (not (contains? result :alias))))))))
|
||||
|
||||
(deftest search-result-replaces-page-title-uuid-refs-without-alias-title
|
||||
(testing "page result titles resolve uuid refs but do not display alias titles from the search index"
|
||||
(let [page-id #uuid "00000000-0000-0000-0000-000000000246"
|
||||
ref-id #uuid "00000000-0000-0000-0000-000000000247"
|
||||
page {:db/id 1
|
||||
:block/uuid page-id
|
||||
:block/title (str "Artificial [[" ref-id "]]")
|
||||
:block/refs [{:block/uuid ref-id
|
||||
:block/title "Machine Learning"}]
|
||||
:block/alias [{:db/id 2
|
||||
:block/uuid #uuid "00000000-0000-0000-0000-000000000248"
|
||||
:block/title "ai"}]}]
|
||||
(with-redefs [d/entity (fn [_db [_attr id]]
|
||||
(when (= id page-id)
|
||||
page))
|
||||
ldb/page? (fn [entity] (= (:db/id entity) (:db/id page)))
|
||||
ldb/object? (constantly false)
|
||||
ldb/built-in? (constantly false)
|
||||
ldb/hidden? (constantly false)]
|
||||
(let [result (#'search/search-result->block-result
|
||||
(atom :db)
|
||||
"Artificial"
|
||||
nil
|
||||
{:enable-snippet? false}
|
||||
{:id (str page-id)
|
||||
:page (str page-id)
|
||||
:title "Artificial [[Machine Learning]] ai"})]
|
||||
(is (= "Artificial [[Machine Learning]]" (:block/title result)))
|
||||
(is (not (contains? result :alias))))))))
|
||||
|
||||
(deftest search-result-snippet-uses-canonical-page-title
|
||||
(testing "page snippets do not display alias titles from the search index"
|
||||
(let [page-id #uuid "00000000-0000-0000-0000-000000000242"
|
||||
|
||||
Reference in New Issue
Block a user