From a07315cec2f4d329ebb33802d106ab1d140a94b5 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Mon, 20 Apr 2026 23:23:50 +0100 Subject: [PATCH] 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 --- src/lib/components/ui/LocationSearchBox.svelte | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) 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);