diff --git a/src/lib/components/ui/LocationSearchBox.svelte b/src/lib/components/ui/LocationSearchBox.svelte index 31ca9e5..83510af 100644 --- a/src/lib/components/ui/LocationSearchBox.svelte +++ b/src/lib/components/ui/LocationSearchBox.svelte @@ -33,9 +33,21 @@ 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; // Alphabetical Sort return a.n.localeCompare(b.n);