mirror of
https://github.com/bitwarden/browser.git
synced 2024-08-25 23:03:07 +02:00
searchCiphersBasic
This commit is contained in:
parent
364192b27a
commit
bdb2efd770
|
@ -5,4 +5,5 @@ export abstract class SearchService {
|
||||||
isSearchable: (query: string) => boolean;
|
isSearchable: (query: string) => boolean;
|
||||||
indexCiphers: () => Promise<void>;
|
indexCiphers: () => Promise<void>;
|
||||||
searchCiphers: (query: string, filter?: (cipher: CipherView) => boolean) => Promise<CipherView[]>;
|
searchCiphers: (query: string, filter?: (cipher: CipherView) => boolean) => Promise<CipherView[]>;
|
||||||
|
searchCiphersBasic: (ciphers: CipherView[], query: string) => CipherView[];
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,10 +67,12 @@ export class CipherService implements CipherServiceAbstraction {
|
||||||
}
|
}
|
||||||
set decryptedCipherCache(value: CipherView[]) {
|
set decryptedCipherCache(value: CipherView[]) {
|
||||||
this._decryptedCipherCache = value;
|
this._decryptedCipherCache = value;
|
||||||
if (value == null) {
|
if (this.searchService != null) {
|
||||||
this.searchService().clearIndex();
|
if (value == null) {
|
||||||
} else {
|
this.searchService().clearIndex();
|
||||||
this.searchService().indexCiphers();
|
} else {
|
||||||
|
this.searchService().indexCiphers();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -103,24 +103,7 @@ export class SearchService implements SearchServiceAbstraction {
|
||||||
|
|
||||||
if (this.index == null) {
|
if (this.index == null) {
|
||||||
// Fall back to basic search if index is not available
|
// Fall back to basic search if index is not available
|
||||||
return ciphers.filter((c) => {
|
return this.searchCiphersBasic(ciphers, query);
|
||||||
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;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const ciphersMap = new Map<string, CipherView>();
|
const ciphersMap = new Map<string, CipherView>();
|
||||||
|
@ -157,4 +140,26 @@ export class SearchService implements SearchServiceAbstraction {
|
||||||
}
|
}
|
||||||
return results;
|
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;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user