1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-17 15:37:57 +01:00

searchCiphersBasic

This commit is contained in:
Kyle Spearrin 2018-08-13 14:28:10 -04:00
parent 364192b27a
commit bdb2efd770
3 changed files with 30 additions and 22 deletions

View File

@ -5,4 +5,5 @@ export abstract class SearchService {
isSearchable: (query: string) => boolean;
indexCiphers: () => Promise<void>;
searchCiphers: (query: string, filter?: (cipher: CipherView) => boolean) => Promise<CipherView[]>;
searchCiphersBasic: (ciphers: CipherView[], query: string) => CipherView[];
}

View File

@ -67,12 +67,14 @@ export class CipherService implements CipherServiceAbstraction {
}
set decryptedCipherCache(value: CipherView[]) {
this._decryptedCipherCache = value;
if (this.searchService != null) {
if (value == null) {
this.searchService().clearIndex();
} else {
this.searchService().indexCiphers();
}
}
}
clearCache(): void {
this.decryptedCipherCache = null;

View File

@ -103,24 +103,7 @@ export class SearchService implements SearchServiceAbstraction {
if (this.index == null) {
// Fall back to basic search if index is not available
return ciphers.filter((c) => {
if (c.name != null && c.name.toLowerCase().indexOf(query) > -1) {
return true;
}
if (this.onlySearchName) {
return false;
}
if (query.length >= 8 && c.id.startsWith(query)) {
return true;
}
if (c.subTitle != null && c.subTitle.toLowerCase().indexOf(query) > -1) {
return true;
}
if (c.login && c.login.uri != null && c.login.uri.toLowerCase().indexOf(query) > -1) {
return true;
}
return false;
});
return this.searchCiphersBasic(ciphers, query);
}
const ciphersMap = new Map<string, CipherView>();
@ -157,4 +140,26 @@ export class SearchService implements SearchServiceAbstraction {
}
return results;
}
searchCiphersBasic(ciphers: CipherView[], query: string) {
query = query.trim().toLowerCase();
return ciphers.filter((c) => {
if (c.name != null && c.name.toLowerCase().indexOf(query) > -1) {
return true;
}
if (this.onlySearchName) {
return false;
}
if (query.length >= 8 && c.id.startsWith(query)) {
return true;
}
if (c.subTitle != null && c.subTitle.toLowerCase().indexOf(query) > -1) {
return true;
}
if (c.login && c.login.uri != null && c.login.uri.toLowerCase().indexOf(query) > -1) {
return true;
}
return false;
});
}
}