Skip to content

Commit 8954f04

Browse files
committed
[native] fix(Search): Match partial words
but sort them under full-word matches fixes #1801 Signed-off-by: Marcel Klehr <[email protected]>
1 parent 8ebad4b commit 8954f04

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/ui/views/native/Tree.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,9 +603,15 @@ export default {
603603
search(query, tree) {
604604
return Object.values(tree.index.bookmark)
605605
.filter(item => {
606-
const matchTitle = item.title ? query.split(' ').every(term => item.title.toLowerCase().split(' ').some(word => word === term)) : false
606+
const matchTitleFully = item.title ? query.split(' ').every(term => item.title.toLowerCase().split(' ').some(word => word === term)) : false
607+
const matchTitlePartially = item.title ? query.split(' ').every(term => item.title.toLowerCase().includes(term)) : false
607608
const matchUrl = query.split(' ').every(term => item.url.toLowerCase().includes(term))
608-
return matchUrl || matchTitle
609+
return matchUrl || matchTitleFully || matchTitlePartially
610+
})
611+
.sort((a, b) => {
612+
const matchTitlePartiallyA = a.title ? query.split(' ').every(term => a.title.toLowerCase().includes(term)) : false
613+
const matchTitlePartiallyB = b.title ? query.split(' ').every(term => b.title.toLowerCase().includes(term)) : false
614+
return matchTitlePartiallyA ? (matchTitlePartiallyB ? 0 : -1) : 1
609615
})
610616
.sort((a, b) => {
611617
const matchTitleA = a.title ? query.split(' ').every(term => a.title.toLowerCase().split(' ').some(word => word === term)) : false

0 commit comments

Comments
 (0)