718
}
719
720
>
function compareByMatchLength(matchesA?: IMatch[], matchesB?: IMatch[]): number {
fuzzyScorer.ts
721
>
if ((!matchesA && !matchesB) || ((!matchesA?.length) && (!matchesB?.length))) {
722
return 0; // make sure to not cause bad comparing when matches are not provided
723
}
725
>
if (!matchesB?.length) {
726
return -1;
727
}
729
>
if (!matchesA?.length) {
730
return 1;
731
}
733
>
// Compute match length of A (first to last match)
734
>
const matchStartA = matchesA[0].start;
735
>
const matchEndA = matchesA[matchesA.length - 1].end;
736
>
const matchLengthA = matchEndA - matchStartA;
737
>
738
>
// Compute match length of B (first to last match)
739
>
const matchStartB = matchesB[0].start;
740
>
const matchEndB = matchesB[matchesB.length - 1].end;
741
>
const matchLengthB = matchEndB - matchStartB;
742
>
743
>
// Prefer shorter match length
744
>
return matchLengthA === matchLengthB ? 0 : matchLengthB < matchLengthA ? 1 : -1;
745
>
}
746
747
function fallbackCompare<T>(itemA: T, itemB: T, query: IPreparedQuery, accessor: IItemAccessor<T>): number {