We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 645cc49 commit ecbdea6Copy full SHA for ecbdea6
1 file changed
js/crsearch/database.js
@@ -70,7 +70,7 @@ export default class Database {
70
targets.push(...ns.query(q))
71
}
72
73
- // 検索クエリとの完全一致を優先するソート
+ // 検索クエリとの完全一致を優先し、次に最短マッチを優先するソート
74
const grouped_targets = targets.sort((aidx, bidx) => {
75
// 名前の最後の部分(名前空間を除いた部分)を取得
76
const getLastPart = (name) => {
@@ -94,7 +94,12 @@ export default class Database {
94
if (aExactPart && !bExactPart) return -1
95
if (!aExactPart && bExactPart) return 1
96
97
- // 完全一致でない場合、元のcompareロジックを使用
+ // 最短マッチを優先: 名前の長さでソート(短い方を優先)
98
+ const aLen = aidx._name.length
99
+ const bLen = bidx._name.length
100
+ if (aLen !== bLen) return aLen - bLen
101
+
102
+ // 長さが同じ場合、元のcompareロジックを使用
103
return Index.compare(aidx, bidx)
104
}).slice(0, max_count).reduce(
105
(gr, index) => {
0 commit comments