Просмотр исходного кода

fix: add score for non-matched results

Tienson Qin 6 месяцев назад
Родитель
Сommit
a9e9149350
2 измененных файлов с 8 добавлено и 7 удалено
  1. 1 1
      src/main/frontend/worker/embedding.cljs
  2. 7 6
      src/main/frontend/worker/search.cljs

+ 1 - 1
src/main/frontend/worker/embedding.cljs

@@ -264,7 +264,7 @@
                          ;; (prn :debug :semantic-search-result
                          ;; (prn :debug :semantic-search-result
                          ;;      :block (:block/title (d/entity @conn label))
                          ;;      :block (:block/title (d/entity @conn label))
                          ;;      :distance distance)
                          ;;      :distance distance)
-                         (when-not (or (js/isNaN distance) (>= distance 0.3)
+                         (when-not (or (js/isNaN distance) (>= distance 0.45)
                                        (> label 2147483647))
                                        (> label 2147483647))
                            (when-let [block (d/entity @conn label)]
                            (when-let [block (d/entity @conn label)]
                              (when (:block/title block)
                              (when (:block/title block)

+ 7 - 6
src/main/frontend/worker/search.cljs

@@ -328,9 +328,9 @@ DROP TRIGGER IF EXISTS blocks_au;
                                               (* (:semantic-weight config) s-score)
                                               (* (:semantic-weight config) s-score)
                                               (cond
                                               (cond
                                                 (ldb/page? block)
                                                 (ldb/page? block)
-                                                0.001
+                                                0.02
                                                 (:block/tags block)
                                                 (:block/tags block)
-                                                0.0005
+                                                0.01
                                                 :else
                                                 :else
                                                 0))]
                                                 0))]
                         (merge result
                         (merge result
@@ -374,7 +374,9 @@ DROP TRIGGER IF EXISTS blocks_au;
             matched-result (when-not page-only?
             matched-result (when-not page-only?
                              (search-blocks-aux search-db match-sql q match-input page limit enable-snippet?))
                              (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)
             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?))
+                               (->> (search-blocks-aux search-db non-match-sql q non-match-input page limit enable-snippet?)
+                                    (map (fn [result]
+                                           (assoc result :keyword-score (fuzzy/score q (:title result)))))))
             ;; fuzzy is too slow for large graphs
             ;; fuzzy is too slow for large graphs
             fuzzy-result (when-not (or page large-graph?)
             fuzzy-result (when-not (or page large-graph?)
                            (->> (fuzzy-search repo @conn q option)
                            (->> (fuzzy-search repo @conn q option)
@@ -394,9 +396,8 @@ DROP TRIGGER IF EXISTS blocks_au;
             ;;     (prn :debug :keyword-search-result item))
             ;;     (prn :debug :keyword-search-result item))
             ;; _ (doseq [item semantic-search-result]
             ;; _ (doseq [item semantic-search-result]
             ;;     (prn :debug :semantic-search-item item))
             ;;     (prn :debug :semantic-search-item item))
-            combined-result (combine-results @conn (concat fuzzy-result matched-result) semantic-search-result)
-            result (->> (concat combined-result
-                                non-match-result)
+            combined-result (combine-results @conn (concat fuzzy-result matched-result non-match-result) semantic-search-result)
+            result (->> combined-result
                         (common-util/distinct-by :id)
                         (common-util/distinct-by :id)
                         (keep (fn [result]
                         (keep (fn [result]
                                 (let [{:keys [id page title snippet]} result
                                 (let [{:keys [id page title snippet]} result