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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user