Skip to content

Commit

Permalink
Browser Bookmarks: Always sort the bookmarks by their frecency
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieudutour committed Oct 18, 2023
1 parent 093990c commit c856f80
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
6 changes: 5 additions & 1 deletion extensions/browser-bookmarks/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Browser Bookmarks Changelog

## [Support for Arc] - {PR_MERGE_DATE}
## [Improvements] - 2023-10-18

- Always sort the bookmarks by their frecency

## [Support for Arc] - 2023-09-22

- Add support for `Arc` browser

Expand Down
23 changes: 22 additions & 1 deletion extensions/browser-bookmarks/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ export default function Command() {
{ name: "folder", weight: 0.5 },
],
threshold: 0.4,
includeScore: true,
});
}, [folderBookmarks]);

Expand All @@ -250,7 +251,27 @@ export default function Command() {

const searchResults = fuse.search(query);

return searchResults.map((result) => result.item);
return searchResults
.sort((a, b) => {
// If a has a frecency, but b doesn't, a should come first
if (a.item.bookmarkFrecency && !b.item.bookmarkFrecency) {
return -1;
}

// If b has a frecency, but a doesn't, b should come first
if (!a.item.bookmarkFrecency && b.item.bookmarkFrecency) {
return 1;
}

// If both frecencies are defined,put the one with the higher frecency first
if (a.item.bookmarkFrecency && b.item.bookmarkFrecency) {
return b.item.bookmarkFrecency.frecency - a.item.bookmarkFrecency.frecency;
}

// If both frecencies are undefined, sort by their score
return (a.score || 1) - (a.score || 1);
})
.map((result) => result.item);
}, [folderBookmarks, fuse, query]);

const filteredFolders = useMemo(() => {
Expand Down

0 comments on commit c856f80

Please sign in to comment.