Browse Source

fix: catch match search with escaped input

Also, fixed the problem the highlights don't have spaces around.
Tienson Qin 3 years ago
parent
commit
b658fdb9e8
1 changed files with 17 additions and 10 deletions
  1. 17 10
      src/electron/electron/search.cljs

+ 17 - 10
src/electron/electron/search.cljs

@@ -215,12 +215,15 @@
 
 (defn- search-blocks-aux
   [database sql input page limit]
-  (let [stmt (prepare database sql)]
-    (js->clj
-     (if page
-       (.all ^object stmt (int page) input limit)
-       (.all ^object stmt  input limit))
-     :keywordize-keys true)))
+  (try
+    (let [stmt (prepare database sql)]
+      (js->clj
+       (if page
+         (.all ^object stmt (int page) input limit)
+         (.all ^object stmt  input limit))
+       :keywordize-keys true))
+    (catch :default e
+      (logger/error "Search blocks failed: " (str e)))))
 
 (defn- get-match-inputs
   [q]
@@ -285,9 +288,13 @@
 (defn- search-pages-aux
   [database sql input limit]
   (let [stmt (prepare database sql)]
-    (map search-pages-res-unpack (-> (.raw ^object stmt)
-                                     (.all input limit)
-                                     (js->clj)))))
+    (try
+      (doall
+       (map search-pages-res-unpack (-> (.raw ^object stmt)
+                                        (.all input limit)
+                                        (js->clj))))
+      (catch :default e
+        (logger/error "Search page failed: " (str e))))))
 
 (defn search-pages
   [repo q {:keys [limit]}]
@@ -300,7 +307,7 @@
             ;; the 2nd column in pages_fts (content)
             ;; pfts_2lqh is a key for retrieval
             ;; highlight and snippet only works for some matching with high rank
-            snippet-aux "snippet(pages_fts, 1, '$pfts_2lqh>$', '$<pfts_2lqh$', '...', 32)"
+            snippet-aux "snippet(pages_fts, 1, ' $pfts_2lqh>$ ', ' $<pfts_2lqh$ ', '...', 32)"
             select (str "select rowid, uuid, content, " snippet-aux " from pages_fts where ")
             match-sql (str select
                            " content match ? order by rank limit ?")