[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:
parent
77ca5762e1
commit
1ea2824c24
|
@ -34,7 +34,7 @@ export class SearchService implements SearchServiceAbstraction {
|
||||||
}
|
}
|
||||||
|
|
||||||
isSearchable(query: string): boolean {
|
isSearchable(query: string): boolean {
|
||||||
query = this.normalizeSearchQuery(query);
|
query = SearchService.normalizeSearchQuery(query);
|
||||||
const notSearchable =
|
const notSearchable =
|
||||||
query == null ||
|
query == null ||
|
||||||
(this.index == null && query.length < this.searchableMinLength) ||
|
(this.index == null && query.length < this.searchableMinLength) ||
|
||||||
|
@ -98,7 +98,7 @@ export class SearchService implements SearchServiceAbstraction {
|
||||||
): Promise<CipherView[]> {
|
): Promise<CipherView[]> {
|
||||||
const results: CipherView[] = [];
|
const results: CipherView[] = [];
|
||||||
if (query != null) {
|
if (query != null) {
|
||||||
query = this.normalizeSearchQuery(query.trim().toLowerCase());
|
query = SearchService.normalizeSearchQuery(query.trim().toLowerCase());
|
||||||
}
|
}
|
||||||
if (query === "") {
|
if (query === "") {
|
||||||
query = null;
|
query = null;
|
||||||
|
@ -166,7 +166,7 @@ export class SearchService implements SearchServiceAbstraction {
|
||||||
}
|
}
|
||||||
|
|
||||||
searchCiphersBasic(ciphers: CipherView[], query: string, deleted = false) {
|
searchCiphersBasic(ciphers: CipherView[], query: string, deleted = false) {
|
||||||
query = this.normalizeSearchQuery(query.trim().toLowerCase());
|
query = SearchService.normalizeSearchQuery(query.trim().toLowerCase());
|
||||||
return ciphers.filter((c) => {
|
return ciphers.filter((c) => {
|
||||||
if (deleted !== c.isDeleted) {
|
if (deleted !== c.isDeleted) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -188,7 +188,7 @@ export class SearchService implements SearchServiceAbstraction {
|
||||||
}
|
}
|
||||||
|
|
||||||
searchSends(sends: SendView[], query: string) {
|
searchSends(sends: SendView[], query: string) {
|
||||||
query = this.normalizeSearchQuery(query.trim().toLocaleLowerCase());
|
query = SearchService.normalizeSearchQuery(query.trim().toLocaleLowerCase());
|
||||||
if (query === null) {
|
if (query === null) {
|
||||||
return sends;
|
return sends;
|
||||||
}
|
}
|
||||||
|
@ -295,14 +295,14 @@ export class SearchService implements SearchServiceAbstraction {
|
||||||
const checkFields = fields.every((i: any) => searchableFields.includes(i));
|
const checkFields = fields.every((i: any) => searchableFields.includes(i));
|
||||||
|
|
||||||
if (checkFields) {
|
if (checkFields) {
|
||||||
return this.normalizeSearchQuery(token.toString());
|
return SearchService.normalizeSearchQuery(token.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
return token;
|
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.
|
// 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, "");
|
return query?.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue