Skip to content

Commit

Permalink
[native] fix(Search): Match partial words
Browse files Browse the repository at this point in the history
but sort them under full-word matches

fixes #1801

Signed-off-by: Marcel Klehr <mklehr@gmx.net>
  • Loading branch information
marcelklehr committed Dec 21, 2024
1 parent 8ebad4b commit 8954f04
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/ui/views/native/Tree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -603,9 +603,15 @@ export default {
search(query, tree) {
return Object.values(tree.index.bookmark)
.filter(item => {
const matchTitle = item.title ? query.split(' ').every(term => item.title.toLowerCase().split(' ').some(word => word === term)) : false
const matchTitleFully = item.title ? query.split(' ').every(term => item.title.toLowerCase().split(' ').some(word => word === term)) : false
const matchTitlePartially = item.title ? query.split(' ').every(term => item.title.toLowerCase().includes(term)) : false
const matchUrl = query.split(' ').every(term => item.url.toLowerCase().includes(term))
return matchUrl || matchTitle
return matchUrl || matchTitleFully || matchTitlePartially
})
.sort((a, b) => {
const matchTitlePartiallyA = a.title ? query.split(' ').every(term => a.title.toLowerCase().includes(term)) : false
const matchTitlePartiallyB = b.title ? query.split(' ').every(term => b.title.toLowerCase().includes(term)) : false
return matchTitlePartiallyA ? (matchTitlePartiallyB ? 0 : -1) : 1
})
.sort((a, b) => {
const matchTitleA = a.title ? query.split(' ').every(term => a.title.toLowerCase().split(' ').some(word => word === term)) : false
Expand Down

0 comments on commit 8954f04

Please sign in to comment.