[PS-592] Name field is not prioritised in search results (#808)

* 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 <abispo@bitwarden.com>
This commit is contained in:
André Filipe da Silva Bispo 2022-05-23 10:20:30 +01:00 committed by GitHub
parent e61800d137
commit 400411b7a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 15 deletions

View File

@ -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 {