From e1f1d7e7027fdb1d179aeec29f5a22e706d47a5c Mon Sep 17 00:00:00 2001 From: Matt Gibson Date: Fri, 22 Jan 2021 19:54:22 -0600 Subject: [PATCH] Enable search for sends (#249) --- src/abstractions/search.service.ts | 2 ++ src/services/search.service.ts | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/abstractions/search.service.ts b/src/abstractions/search.service.ts index d6d0364faf..127a970353 100644 --- a/src/abstractions/search.service.ts +++ b/src/abstractions/search.service.ts @@ -1,4 +1,5 @@ import { CipherView } from '../models/view/cipherView'; +import { SendView } from '../models/view/sendView'; export abstract class SearchService { clearIndex: () => void; @@ -8,4 +9,5 @@ export abstract class SearchService { filter?: ((cipher: CipherView) => boolean) | (((cipher: CipherView) => boolean)[]), ciphers?: CipherView[]) => Promise; searchCiphersBasic: (ciphers: CipherView[], query: string, deleted?: boolean) => CipherView[]; + searchSends: (sends: SendView[], query: string) => SendView[]; } diff --git a/src/services/search.service.ts b/src/services/search.service.ts index 4a7207f93b..0552ffc8c4 100644 --- a/src/services/search.service.ts +++ b/src/services/search.service.ts @@ -9,6 +9,7 @@ import { SearchService as SearchServiceAbstraction } from '../abstractions/searc import { CipherType } from '../enums/cipherType'; import { FieldType } from '../enums/fieldType'; import { UriMatchType } from '../enums/uriMatchType'; +import { SendView } from '../models/view/sendView'; export class SearchService implements SearchServiceAbstraction { private indexing = false; @@ -161,6 +162,28 @@ export class SearchService implements SearchServiceAbstraction { }); } + searchSends(sends: SendView[], query: string) { + query = query.trim().toLocaleLowerCase(); + + return sends.filter(s => { + if (s.name != null && s.name.toLowerCase().indexOf(query) > -1) { + return true; + } + if (query.length >= 8 && (s.id.startsWith(query) || (s.file?.id != null && s.file.id.startsWith(query)))) { + return true; + } + if (s.notes != null && s.notes.toLowerCase().indexOf(query) > -1) { + return true; + } + if (s.text?.text != null && s.text.text.toLowerCase().indexOf(query) > -1) { + return true; + } + if (s.file?.fileName != null && s.file.fileName.toLowerCase().indexOf(query) > -1) { + return true; + } + }); + } + getIndexForSearch(): lunr.Index { return this.index; }