25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(grid): rank column lookup results by identifier match score (#13103)
lxk955adfecc8ed783
diff --git a/apps/desktop/src/lib/__tests__/dataGridColumnLookup.spec.ts b/apps/desktop/src/lib/__tests__/dataGridColumnLookup.spec.tsindex 62b5dea0e3..f8ae96cc20 100644--- a/apps/desktop/src/lib/__tests__/dataGridColumnLookup.spec.ts+++ b/apps/desktop/src/lib/__tests__/dataGridColumnLookup.spec.ts@@ -74,4 +74,51 @@ describe("data grid column lookup search", () => {}),).toEqual([{ index: 0, name: "total" }]);});++ it("ranks prefix matches ahead of distant fuzzy subsequence matches (issue #13045)", () => {+ const lookupItems = buildDataGridColumnLookupItems({+ columns: ["iiitdjdahg", "tagunique"],+ });++ const result = filterDataGridColumnLookupItems(lookupItems, "tag");+ expect(result.map((item) => item.name)).toEqual(["tagunique", "iiitdjdahg"]);+ });++ it("ranks exact match ahead of prefix, substring, and fuzzy matches", () => {+ const lookupItems = buildDataGridColumnLookupItems({+ columns: ["tag_id", "contain_tag", "tag", "iiitdjdahg"],+ });++ const result = filterDataGridColumnLookupItems(lookupItems, "tag");+ expect(result.map((item) => item.name)).toEqual(["tag", "tag_id", "contain_tag", "iiitdjdahg"]);+ });++ it("ranks column name matches ahead of comment matches", () => {+ const lookupItems = buildDataGridColumnLookupItems({+ columns: ["status", "category"],+ columnComments: ["category type", "status code"],+ });++ const result = filterDataGridColumnLookupItems(lookupItems, "category");+ expect(result.map((item) => item.name)).toEqual(["category", "status"]);+ });++ it("breaks ties with original column order", () => {+ const lookupItems = buildDataGridColumnLookupItems({+ columns: ["tag_one", "tag_two", "tag_six"],+ });++ const result = filterDataGridColumnLookupItems(lookupItems, "tag_");+ expect(result.map((item) => item.name)).toEqual(["tag_one", "tag_two", "tag_six"]);+ });++ it("ranks name matches ahead of sourceName matches in exact mode", () => {+ const lookupItems = buildDataGridColumnLookupItems({+ columns: ["alias_tag", "tag"],+ sourceColumns: ["tag", "physical_tag"],+ });++ const result = filterDataGridColumnLookupItems(lookupItems, "tag", "exact");+ expect(result.map((item) => item.name)).toEqual(["tag", "alias_tag"]);+ });});diff --git a/apps/desktop/src/lib/dataGrid/dataGridColumnLookup.ts b/apps/desktop/src/lib/dataGrid/dataGridColumnLookup.tsindex 09c189fece..1b177ecc3c 100644--- a/apps/desktop/src/lib/dataGrid/dataGridColumnLookup.ts+++ b/apps/desktop/src/lib/dataGrid/dataGridColumnLookup.ts@@ -1,4 +1,4 @@-import { matchesIdentifierSearch } from "@/lib/sql/identifierSearch";+import { identifierMatchScore } from "@/lib/sql/identifierSearch";export interface DataGridColumnLookupItem {index: number;@@ -53,12 +53,42 @@ export function buildDataGridColumnLookupItems(options: DataGridColumnLookupOpti});}+export function scoreDataGridColumnLookupItem(item: DataGridColumnLookupItem, query: string): number {+ const normalizedQuery = normalizedSearchText(query);+ if (!normalizedQuery) return 1;+ const nameScore = identifierMatchScore(item.name, normalizedQuery);+ const sourceScore = item.sourceName ? identifierMatchScore(item.sourceName, normalizedQuery) : -1;+ const commentScore = item.comment ? identifierMatchScore(item.comment, normalizedQuery) : -1;+ const effectiveCommentScore = commentScore >= 0 ? Math.max(0, commentScore - 50) : -1;+ return Math.max(nameScore, sourceScore, effectiveCommentScore);+}+export function filterDataGridColumnLookupItems<ColumnLookupItem extends DataGridColumnLookupItem>(items: readonly ColumnLookupItem[], query: string, matchMode: DataGridColumnLookupMatchMode = "fuzzy"): ColumnLookupItem[] {const normalizedQuery = normalizedSearchText(query);if (!normalizedQuery) return [...items];+if (matchMode === "exact") {const normalizedQueryLower = normalizedQuery.toLocaleLowerCase();- return items.filter((item) => [item.name, item.sourceName].filter((value): value is string => !!value).some((value) => value.trim().toLocaleLowerCase() === normalizedQueryLower));+ const scored: { item: ColumnLookupItem; score: number; order: number }[] = [];+ for (let i = 0; i < items.length; i++) {+ const item = items[i];+ const nameMatch = item.name.trim().toLocaleLowerCase() === normalizedQueryLower;+ const sourceMatch = item.sourceName?.trim().toLocaleLowerCase() === normalizedQueryLower;+ if (nameMatch || sourceMatch) {+ const score = nameMatch ? 2 : 1;+ scored.push({ item, score, order: i });+ }+ }+ return scored.sort((a, b) => b.score - a.score || a.order - b.order).map((entry) => entry.item);+ }++ const scored: { item: ColumnLookupItem; score: number; order: number }[] = [];+ for (let i = 0; i < items.length; i++) {+ const item = items[i];+ const score = scoreDataGridColumnLookupItem(item, normalizedQuery);+ if (score >= 0) {+ scored.push({ item, score, order: i });+ }}- return items.filter((item) => [item.name, item.sourceName, item.comment].filter((value): value is string => !!value).some((value) => matchesIdentifierSearch(value, normalizedQuery)));+ return scored.sort((a, b) => b.score - a.score || a.order - b.order).map((entry) => entry.item);}