Browse Source

adjust page/object sorting weight

Tienson Qin 5 months ago
parent
commit
d488c53fd6

+ 1 - 1
deps/outliner/src/logseq/outliner/core.cljs

@@ -251,7 +251,7 @@
           collapse-or-expand? (= outliner-op :collapse-expand-blocks)
           m* (cond->
               (-> data'
-                  (dissoc :block/children :block/meta :block/unordered
+                  (dissoc :block/children :block/meta :block/unordered :block/path-refs
                           :block.temp/ast-title :block.temp/ast-body :block/level :block.temp/load-status
                           :block.temp/has-children?)
                   common-util/remove-nils

+ 8 - 5
deps/outliner/src/logseq/outliner/pipeline.cljs

@@ -50,7 +50,7 @@
                                    (recur (into parent-refs (:block-ref-ids parent))
                                           (:parent-id parent))
                                    ;; exits when top-level parent is reached
-                                   parent-refs)))})
+                                   (remove nil? parent-refs))))})
                            children-maps)]
     children-refs))
 
@@ -87,10 +87,13 @@
                        old-refs (if db-before
                                   (set (map :db/id (:block/path-refs (d/entity db-before (:db/id block)))))
                                   #{})
-                       new-refs (set (concat
-                                      (some-> (:db/id (:block/page block)) vector)
-                                      (map :db/id (:block/refs block))
-                                      parents-refs))
+                       new-refs (->>
+                                 (concat
+                                  (some-> (:db/id (:block/page block)) vector)
+                                  (map :db/id (:block/refs block))
+                                  parents-refs)
+                                 (remove nil?)
+                                 set)
                        refs-changed? (not= old-refs new-refs)
                        children (when refs-changed?
                                   (when-not page?

+ 1 - 1
src/main/frontend/components/settings.cljs

@@ -1258,7 +1258,7 @@
              (for [model-name (:available-model-names model-info)]
                (shui/select-item {:value model-name} model-name)))))
 
-          (when status
+          (when (and status current-model)
             [:div.text-muted-foreground.text-sm
              (let [{:keys [file progress loaded total]} load-model-progress]
                (case status

+ 10 - 8
src/main/frontend/worker/embedding.cljs

@@ -79,14 +79,16 @@
               (filter (stale-block-filter-preds reset?))
               (map (fn [b]
                      (assoc b :block.temp/text-to-embedding
-                            (str (db-content/recur-replace-uuid-in-block-title b)
-                                 (let [tags (->> (:block/tags b)
-                                                 (map :block/title))]
-                                   (when (seq tags)
-                                     (str " tags: " (string/join ", " tags))))
-                                 (when-let [desc (:block/title (:logseq.property/description b))]
-                                   (str " description: " desc))))))))))
-
+                            (db-content/recur-replace-uuid-in-block-title b)
+                            ;; FIXME: tags and properties can affect sorting
+                            ;; (str (db-content/recur-replace-uuid-in-block-title b)
+                            ;;      (let [tags (->> (:block/tags b)
+                            ;;                      (map :block/title))]
+                            ;;        (when (seq tags)
+                            ;;          (str " " (string/join ", " (map (fn [t] (str "#" t)) tags)))))
+                            ;;      (when-let [desc (:block/title (:logseq.property/description b))]
+                            ;;        (str "\nDescription: " desc)))
+                            )))))))
 (defn- partition-by-text-size
   [text-size]
   (let [*current-size (volatile! 0)

+ 20 - 18
src/main/frontend/worker/search.cljs

@@ -299,37 +299,39 @@ DROP TRIGGER IF EXISTS blocks_au;
                          (exact-matched? q title)))))))))
 
 ;; Combine and re-rank results
-(defn combine-results [keyword-results semantic-results]
+(defn combine-results
+  [db keyword-results semantic-results]
   (let [;; Extract score ranges for normalization
         keyword-scores (map :keyword-score keyword-results)
-        semantic-scores (map :semantic-score semantic-results)
         k-min (if (seq keyword-scores) (apply min keyword-scores) 0.0)
         k-max (if (seq keyword-scores) (apply max keyword-scores) 1.0)
-        s-min (if (seq semantic-scores) (apply min semantic-scores) 0.0)
-        s-max (if (seq semantic-scores) (apply max semantic-scores) 1.0)
-        ;; Merge results by ID
         all-ids (set/union (set (map :id keyword-results))
                            (set (map :id semantic-results)))
         merged (map (fn [id]
-                      (let [k-result (first (filter #(= (:id %) id) keyword-results))
+                      (let [block (when id (d/entity db [:block/uuid (uuid id)]))
+                            k-result (first (filter #(= (:id %) id) keyword-results))
                             s-result (first (filter #(= (:id %) id) semantic-results))
+                            result (merge s-result k-result)
                             k-score (or (:keyword-score k-result) 0.0)
                             s-score (or (:semantic-score s-result) 0.0)
                             norm-k-score (normalize-score k-score k-min k-max)
-                            norm-s-score (normalize-score s-score s-min s-max)
                             ;; Weighted combination
                             combined-score (+ (* (:keyword-weight config) norm-k-score)
-                                              (* (:semantic-weight config) norm-s-score))]
-                        (merge k-result
-                               s-result
-                               {:id id
-                                :combined-score combined-score
+                                              (* (:semantic-weight config) s-score)
+                                              (cond
+                                                (ldb/page? block)
+                                                1
+                                                (:block/tags block)
+                                                0.02
+                                                :else
+                                                0))]
+                        (merge result
+                               {:combined-score combined-score
                                 :keyword-score k-score
                                 :semantic-score s-score})))
-                    all-ids)]
-    ;; Sort by combined score
-    (prn :debug :merged (sort-by :combined-score #(compare %2 %1) merged))
-    (sort-by :combined-score #(compare %2 %1) merged)))
+                    all-ids)
+        sorted-result (sort-by :combined-score #(compare %2 %1) merged)]
+    sorted-result))
 
 (defn search-blocks
   "Options:
@@ -365,7 +367,7 @@ DROP TRIGGER IF EXISTS blocks_au;
                              (search-blocks-aux search-db match-sql q match-input page limit enable-snippet?))
             non-match-result (when (and (not page-only?) non-match-input)
                                (search-blocks-aux search-db non-match-sql q non-match-input page limit enable-snippet?))
-           ;; fuzzy is too slow for large graphs
+            ;; fuzzy is too slow for large graphs
             fuzzy-result (when-not (or page large-graph?) (fuzzy-search repo @conn q option))
             semantic-search-result* (m/? (embedding/task--search repo q 10))
             semantic-search-result (->> semantic-search-result*
@@ -377,7 +379,7 @@ DROP TRIGGER IF EXISTS blocks_au;
                                                    :semantic-score (/ 1.0 (+ 1.0 distance))}
                                                    page-id
                                                    (assoc :page page-id))))))
-            combined-result (combine-results (concat fuzzy-result matched-result) semantic-search-result)
+            combined-result (combine-results @conn (concat fuzzy-result matched-result) semantic-search-result)
             result (->> (concat combined-result
                                 non-match-result)
                         (common-util/distinct-by :id)

+ 1 - 0
src/resources/dicts/en.edn

@@ -214,6 +214,7 @@
  :context-menu/template-include-parent-block "Including the parent block in the template?"
  :context-menu/template-exists-warning "Template already exists!"
  :settings-page/ai "AI"
+ :settings-page/tab-ai "AI"
  :settings-page/git-tip "If you have Logseq Sync enabled, you can view a page's edit history directly. This section is for tech-savvy only."
  :settings-page/git-desc-1 "To view page's edit history, click the three horizontal dots in the top-right corner and select \"View page history\"."
  :settings-page/git-desc-2 "For professional users, Logseq also supports using "