Explorar o código

fix(mobile): build search index with simpler preprocessing rules

See-also: #10771
Andelf %!s(int64=2) %!d(string=hai) anos
pai
achega
402ee7870d
Modificáronse 1 ficheiros con 19 adicións e 2 borrados
  1. 19 2
      src/main/frontend/search/db.cljs

+ 19 - 2
src/main/frontend/search/db.cljs

@@ -20,8 +20,10 @@
   (some-> content
           (util/search-normalize (state/enable-search-remove-accents?))))
 
-(defn block->index
-  "Convert a block to the index for searching"
+(defn- strict-block->index
+  "Convert a block to the index for searching.
+
+   Applies full text preprocessing to the content, including removing built-in properties"
   [{:block/keys [uuid page content format] :as block
     :or {format :markdown}}]
   (when-not (> (count content) (max-len))
@@ -32,6 +34,21 @@
          :page page
          :content (sanitize content)}))))
 
+(defn- loose-block->index
+  "Convert a block to the index for searching
+
+   For speed, applies no preprocessing to the content"
+  [{:block/keys [uuid page content] :as block}]
+  (when-not (string/blank? content)
+    {:id (:db/id block)
+     :uuid (str uuid)
+     :page page
+     :content content}))
+
+(defonce block->index (if (util/electron?)
+                        strict-block->index
+                        loose-block->index))
+
 (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"