789
return 0;
790
}
792
>
//#endregion
793
>
794
>
795
>
//#region Query Normalizer
796
>
797
>
export interface IPreparedQueryPiece {
798
>
799
>
/**
800
>
* The original query as provided as input.
801
>
*/
802
>
original: string;
803
>
originalLowercase: string;
804
>
805
>
/**
806
>
* Original normalized to platform separators:
807
>
* - Windows: \
808
>
* - Posix: /
809
>
*/
810
>
pathNormalized: string;
811
>
812
>
/**
813
>
* In addition to the normalized path, will have
814
>
* whitespace, wildcards, quotes, ellipsis, and trailing hash characters removed.
815
>
*/
816
>
normalized: string;
817
>
normalizedLowercase: string;
818
>
819
>
/**
820
>
* The query is wrapped in quotes which means
821
>
* this query must be a substring of the input.
822
>
* In other words, no fuzzy matching is used.
823
>
*/
824
>
expectContiguousMatch: boolean;
825
>
}
826
>
827
>
export interface IPreparedQuery extends IPreparedQueryPiece {
828
>
829
>
/**
830
>
* Query split by spaces into pieces.
831
>
*/
832
>
values: IPreparedQueryPiece[] | undefined;
833
>
834
>
/**
835
>
* Whether the query contains path separator(s) or not.
836
>
*/
837
>
containsPathSeparator: boolean;
838
>
}
839
>
840
>
/*
841
>
* If a query is wrapped in quotes, the user does not want to
842
>
* use fuzzy search for this query.
843
>
*/
844
function queryExpectsExactMatch(query: string) {
845
return query.startsWith('"') && query.endsWith('"');
846
}
848
>
/**
849
>
* Helper function to prepare a search value for scoring by removing unwanted characters
850
>
* and allowing to score on multiple pieces separated by whitespace character.
851
>
*/
852
>
const MULTIPLE_QUERY_VALUES_SEPARATOR = ' ';
853
>
export function prepareQuery(original: string): IPreparedQuery {
854
if (typeof original !== 'string') {
855
original = '';