From 400411b7a0c0ed75b495bf627b563ff76b5da780 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Filipe=20da=20Silva=20Bispo?= Date: Mon, 23 May 2022 10:20:30 +0100 Subject: [PATCH] [PS-592] Name field is not prioritised in search results (#808) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * PS-592 Name field is not prioritised in search results - test search method which give priority to matches by Name * PS-592 Name field is not prioritised in search results - replaced used method with test method * PS-592 Name field is not prioritised in search results - Fixed code styling * PS-592 Name field is not prioritised in search results - avoid duplicates * PS-592 Name field is not prioritised in search results - let to const * PS-592 - ran prettier and lint Co-authored-by: André Bispo --- common/src/services/search.service.ts | 31 ++++++++++++++------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/common/src/services/search.service.ts b/common/src/services/search.service.ts index 50aa27e8..92e54fad 100644 --- a/common/src/services/search.service.ts +++ b/common/src/services/search.service.ts @@ -188,29 +188,30 @@ export class SearchService implements SearchServiceAbstraction { searchSends(sends: SendView[], query: string) { query = query.trim().toLocaleLowerCase(); - - return sends.filter((s) => { + if (query === null) { + return sends; + } + const sendsMatched: SendView[] = []; + const lowPriorityMatched: SendView[] = []; + sends.forEach((s) => { if (s.name != null && s.name.toLowerCase().indexOf(query) > -1) { - return true; - } - if ( + sendsMatched.push(s); + } else if ( query.length >= 8 && (s.id.startsWith(query) || s.accessId.toLocaleLowerCase().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; + lowPriorityMatched.push(s); + } else if (s.notes != null && s.notes.toLowerCase().indexOf(query) > -1) { + lowPriorityMatched.push(s); + } else if (s.text?.text != null && s.text.text.toLowerCase().indexOf(query) > -1) { + lowPriorityMatched.push(s); + } else if (s.file?.fileName != null && s.file.fileName.toLowerCase().indexOf(query) > -1) { + lowPriorityMatched.push(s); } }); + return sendsMatched.concat(lowPriorityMatched); } getIndexForSearch(): lunr.Index {