[ps-136] Moved normalizeSearchQuery method to Utils (#817)

* stripped off accented characters from search field for browser client

* moved normalization from component to search service

* fixed conflicts

* removed normalization from cipher component

* added comments to normalize method

* added comments to normalize method

* fixed bug with calling normalizeSearchQuery methid in pipeline function

* ran prettier

* moved normalization function to utils

* made normalization function a static function

* remove unused reference
This commit is contained in:
Gbubemi Smith 2022-05-27 14:50:08 +01:00 committed by GitHub
parent 77ca5762e1
commit 1ea2824c24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 6 deletions

View File

@ -34,7 +34,7 @@ export class SearchService implements SearchServiceAbstraction {
}
isSearchable(query: string): boolean {
query = this.normalizeSearchQuery(query);
query = SearchService.normalizeSearchQuery(query);
const notSearchable =
query == null ||
(this.index == null && query.length < this.searchableMinLength) ||
@ -98,7 +98,7 @@ export class SearchService implements SearchServiceAbstraction {
): Promise<CipherView[]> {
const results: CipherView[] = [];
if (query != null) {
query = this.normalizeSearchQuery(query.trim().toLowerCase());
query = SearchService.normalizeSearchQuery(query.trim().toLowerCase());
}
if (query === "") {
query = null;
@ -166,7 +166,7 @@ export class SearchService implements SearchServiceAbstraction {
}
searchCiphersBasic(ciphers: CipherView[], query: string, deleted = false) {
query = this.normalizeSearchQuery(query.trim().toLowerCase());
query = SearchService.normalizeSearchQuery(query.trim().toLowerCase());
return ciphers.filter((c) => {
if (deleted !== c.isDeleted) {
return false;
@ -188,7 +188,7 @@ export class SearchService implements SearchServiceAbstraction {
}
searchSends(sends: SendView[], query: string) {
query = this.normalizeSearchQuery(query.trim().toLocaleLowerCase());
query = SearchService.normalizeSearchQuery(query.trim().toLocaleLowerCase());
if (query === null) {
return sends;
}
@ -295,14 +295,14 @@ export class SearchService implements SearchServiceAbstraction {
const checkFields = fields.every((i: any) => searchableFields.includes(i));
if (checkFields) {
return this.normalizeSearchQuery(token.toString());
return SearchService.normalizeSearchQuery(token.toString());
}
return token;
}
// Remove accents/diacritics characters from text. This regex is equivalent to the Diacritic unicode property escape, i.e. it will match all diacritic characters.
private normalizeSearchQuery(query: string): string {
static normalizeSearchQuery(query: string): string {
return query?.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
}
}