Fix search priority:

1. Match to exact CRS
 2. Match to exact Name
 3. Match to 'Name startsWith'
 4. Match any with valid CRS
 5. Match alphabetically
This commit is contained in:
2026-04-20 23:23:50 +01:00
parent f3393f3c07
commit a07315cec2

View File

@@ -33,9 +33,21 @@
if (aExactCrs && !bExactCrs) return -1; if (aExactCrs && !bExactCrs) return -1;
if (!aExactCrs && bExactCrs) return 1; if (!aExactCrs && bExactCrs) return 1;
// Priority Two - 'Stations' with CRS // Priority Two - Exact Name Match
const aNameLow = a.n.toLowerCase();
const bNameLow = b.n.toLowerCase();
const aExactName = aNameLow === lowerQuery;
const bExactName = bNameLow === lowerQuery;
if (aExactName !== bExactName) return aExactName ? -1 : 1;
// Priority Three - Name starts with Query
const aStarts = aNameLow.startsWith(lowerQuery);
const bStarts = bNameLow.startsWith(lowerQuery);
if (aStarts !== bStarts) return aStarts ? -1 : 1;
// Priority Four - 'Stations' with CRS
if (!!a.c && !b.c) return -1; if (!!a.c && !b.c) return -1;
if (!a.c & !!b.c) return 1; if (!a.c && !!b.c) return 1;
// Alphabetical Sort // Alphabetical Sort
return a.n.localeCompare(b.n); return a.n.localeCompare(b.n);