fix(core): prefer shorter paths for tied search scores
This commit is contained in:
@@ -202,18 +202,30 @@ export const fffLayer = Layer.effect(
|
|||||||
if (input.type === "file") {
|
if (input.type === "file") {
|
||||||
const found = result.value.fileSearch(input.query.trim(), options)
|
const found = result.value.fileSearch(input.query.trim(), options)
|
||||||
if (!found.ok) throw found.error
|
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") {
|
if (input.type === "directory") {
|
||||||
const found = result.value.directorySearch(input.query.trim(), options)
|
const found = result.value.directorySearch(input.query.trim(), options)
|
||||||
if (!found.ok) throw found.error
|
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)
|
const found = result.value.mixedSearch(input.query.trim(), options)
|
||||||
if (!found.ok) throw found.error
|
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 relative = item.path.replaceAll("\\", "/").replace(/\/$/, "")
|
||||||
const absolute = path.resolve(location.directory, relative)
|
const absolute = path.resolve(location.directory, relative)
|
||||||
return new FileSystem.Entry({
|
return new FileSystem.Entry({
|
||||||
|
|||||||
Reference in New Issue
Block a user