Skip to content

Commit 1868c52

Browse files
committed
enh: Improve search
Signed-off-by: Marcel Klehr <[email protected]>
1 parent a9be249 commit 1868c52

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/ui/views/native/Tree.vue

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ export default {
382382
}
383383
let items
384384
if (this.searchQuery && this.searchQuery.length >= 2) {
385-
items = this.search(this.searchQuery.toLowerCase().trim(), this.currentFolder)
385+
return this.search(this.searchQuery.toLowerCase().trim(), this.currentFolder)
386386
} else {
387387
items = this.currentFolder.children
388388
}
@@ -466,11 +466,17 @@ export default {
466466
}, 500)
467467
},
468468
search(query, tree) {
469-
return Object.values(tree.index.bookmark).filter(item => {
470-
const matchTitle = item.title ? query.split(' ').every(term => item.title.toLowerCase().includes(term)) : false
471-
const matchUrl = query.split(' ').every(term => item.url.toLowerCase().includes(term))
472-
return matchUrl || matchTitle
473-
})
469+
return Object.values(tree.index.bookmark)
470+
.filter(item => {
471+
const matchTitle = item.title ? query.split(' ').every(term => item.title.toLowerCase().split(' ').some(word => word === term)) : false
472+
const matchUrl = query.split(' ').every(term => item.url.toLowerCase().includes(term))
473+
return matchUrl || matchTitle
474+
})
475+
.sort((a, b) => {
476+
const matchTitleA = a.title ? query.split(' ').every(term => a.title.toLowerCase().split(' ').some(word => word === term)) : false
477+
const matchTitleB = b.title ? query.split(' ').every(term => b.title.toLowerCase().split(' ').some(word => word === term)) : false
478+
return matchTitleA ? (matchTitleB ? 0 : -1) : 1
479+
})
474480
},
475481
goBack() {
476482
if (this.isAddingBookmark) {

0 commit comments

Comments
 (0)