Skip to content

Commit

Permalink
fix: remove blank string from both pages and blocks in search indice
Browse files Browse the repository at this point in the history
  • Loading branch information
tiensonqin committed Dec 5, 2022
1 parent 96c717f commit a3304ad
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
5 changes: 3 additions & 2 deletions src/main/frontend/search.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
(protocol/transact-blocks! engine data)))

(defn- transact-pages!
[repo data]
[repo data]
(when-let [engine (get-engine repo)]
(protocol/transact-pages! engine data)))

Expand Down Expand Up @@ -216,6 +216,7 @@
(contains? pages-to-add-set (:db/id page))) pages-result)
(map (fn [p] (or (:block/original-name p)
(:block/name p))))
(remove string/blank?)
(map search-db/original-page-name->index))
pages-to-remove-set (->> (remove :added pages)
(map :v))
Expand Down Expand Up @@ -246,7 +247,7 @@
{:blocks-to-remove-set blocks-to-remove-set
:blocks-to-add blocks-to-add})))

(defn- get-direct-blocks-and-pages
(defn- get-direct-blocks-and-pages
[tx-report]
(let [data (:tx-data tx-report)
datoms (filter
Expand Down
30 changes: 17 additions & 13 deletions src/main/frontend/search/db.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

(defn- sanitize
[content]
(util/search-normalize content (state/enable-search-remove-accents?)))
(some-> content
(util/search-normalize (state/enable-search-remove-accents?))))

(defn- max-len
[]
Expand All @@ -22,22 +23,24 @@
"Convert a block to the index for searching"
[{:block/keys [uuid page content] :as block}]
(when-not (> (count content) (max-len))
{:id (:db/id block)
:uuid (str uuid)
:page page
:content (sanitize content)}))
(when-not (string/blank? content)
{:id (:db/id block)
:uuid (str uuid)
:page page
:content (sanitize content)})))

(defn page->index
"Convert a page name to the index for searching (page content level)
Generate index based on the DB content AT THE POINT OF TIME"
[{:block/keys [uuid original-name] :as page}]
(when-let [content (some-> (:block/file page)
(:file/content))]
(when-not (> (count content) (* (max-len) 10))
{:id (:db/id page)
:uuid (str uuid)
;; Add page name to the index
:content (sanitize (str "$pfts_f6ld>$ " original-name " $<pfts_f6ld$ " content))})))
(when-not (string/blank? original-name)
(when-not (> (count content) (* (max-len) 10))
{:id (:db/id page)
:uuid (str uuid)
;; Add page name to the index
:content (sanitize (str "$pfts_f6ld>$ " original-name " $<pfts_f6ld$ " content))}))))

(defn build-blocks-indice
;; TODO: Remove repo effects fns further up the call stack. db fns need standardization on taking connection
Expand All @@ -48,7 +51,7 @@
(remove nil?)
(bean/->js)))

(defn build-pages-indice
(defn build-pages-indice
[repo]
(->> (db/get-all-pages repo)
(map #(db/entity (:db/id %))) ;; get full file-content
Expand All @@ -70,8 +73,9 @@
indice))

(defn original-page-name->index
[p] {:name (util/search-normalize p (state/enable-search-remove-accents?))
:original-name p})
[p]
{:name (util/search-normalize p (state/enable-search-remove-accents?))
:original-name p})

(defn make-pages-title-indice!
"Build a page title indice from scratch.
Expand Down

0 comments on commit a3304ad

Please sign in to comment.