diff --git a/common/src/services/search.service.ts b/common/src/services/search.service.ts index 50aa27e87e..92e54fad6a 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 {