Преглед изворни кода

fix(core): prefer shorter paths for tied search scores

Dax Raad пре 2 месеци
родитељ
комит
4597c687fa
1 измењених фајлова са 16 додато и 4 уклоњено
  1. 16 4
      packages/core/src/filesystem/search.ts

+ 16 - 4
packages/core/src/filesystem/search.ts

@@ -202,18 +202,30 @@ export const fffLayer = Layer.effect(
             if (input.type === "file") {
               const found = result.value.fileSearch(input.query.trim(), options)
               if (!found.ok) throw found.error
-              return found.value.items.map((item) => ({ path: item.relativePath, type: "file" as const }))
+              return found.value.items.map((item, index) => ({
+                path: item.relativePath,
+                type: "file" as const,
+                score: found.value.scores[index]?.total ?? 0,
+              }))
             }
             if (input.type === "directory") {
               const found = result.value.directorySearch(input.query.trim(), options)
               if (!found.ok) throw found.error
-              return found.value.items.map((item) => ({ path: item.relativePath, type: "directory" as const }))
+              return found.value.items.map((item, index) => ({
+                path: item.relativePath,
+                type: "directory" as const,
+                score: found.value.scores[index]?.total ?? 0,
+              }))
             }
             const found = result.value.mixedSearch(input.query.trim(), options)
             if (!found.ok) throw found.error
-            return found.value.items.map((item) => ({ path: item.item.relativePath, type: item.type }))
+            return found.value.items.map((item, index) => ({
+              path: item.item.relativePath,
+              type: item.type,
+              score: found.value.scores[index]?.total ?? 0,
+            }))
           })()
-          return items.map((item) => {
+          return items.sort((a, b) => b.score - a.score || a.path.length - b.path.length).map((item) => {
             const relative = item.path.replaceAll("\\", "/").replace(/\/$/, "")
             const absolute = path.resolve(location.directory, relative)
             return new FileSystem.Entry({