Jelajahi Sumber

enhance: re-enable full-text query on the desktop app

Notice: it doesn't support reactive query
Tienson Qin 4 tahun lalu
induk
melakukan
264b734111

+ 18 - 8
src/main/frontend/components/block.cljs

@@ -1873,18 +1873,28 @@
 (defn- trigger-custom-query!
   [state]
   (let [[config query] (:rum/args state)
+        repo (state/get-current-repo)
+        result-atom (atom nil)
         query-atom (if (:dsl-query? config)
                      (let [result (query-dsl/query (state/get-current-repo) (:query query))]
-                       (if (string? result) ; full-text search
+                       (cond
+                         (and (util/electron?) (string? result)) ; full-text search
+                         (if (string/blank? result)
+                           (atom [])
+                           (p/let [blocks (search/block-search repo result {})]
+                             (when (seq blocks)
+                               (let [result (db/pull-many (state/get-current-repo) '[*] (map (fn [b] [:block/uuid (uuid (:block/uuid b))]) blocks))]
+                                 (reset! result-atom result)))))
+
+                         (string? result)
                          (atom nil)
-                         ;; (atom
-                         ;;  (if (string/blank? result)
-                         ;;    []
-                         ;;    (let [blocks (search/block-search result 50)]
-                         ;;      (when (seq blocks)
-                         ;;        (db/pull-many (state/get-current-repo) '[*] (map (fn [b] [:block/uuid (uuid (:block/uuid b))]) blocks))))))
+
+                         :else
                          result))
-                     (db/custom-query query))]
+                     (db/custom-query query))
+        query-atom (if (instance? Atom query-atom)
+                     query-atom
+                     result-atom)]
     (assoc state :query-atom query-atom)))
 
 (rum/defcs custom-query < rum/reactive

+ 7 - 1
src/main/frontend/db/query_dsl.cljs

@@ -363,8 +363,14 @@
                   result (when form (build-query repo form {:sort-by sort-by
                                                             :blocks? blocks?
                                                             :counter counter}))]
-              (if (string? result)
+              (cond
+                (and (nil? result) (string? form))
+                form
+
+                (string? result)
                 result
+
+                :else
                 (let [result (when (seq result)
                               (let [key (if (coll? (first result))
                                           (keyword (ffirst result))