Skip to content

fix(search): add new relevance sort order #1392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 18, 2025

Conversation

xuatz
Copy link
Collaborator

@xuatz xuatz commented May 11, 2025

Summary

  • add new sort order relevance
  • retain existing(legacy) search's sort logic as relevance
  • add new asc and desc sort logic

fixes #1335

Notes

I'm wasn't super sure how karakeep handles the translation, so let me know if there are follow up tasks, and anything else that I should tweak for this PR, thanks!

Copy link
Collaborator

@MohamedBassem MohamedBassem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, that was fast @xuatz!

Overall, the PR looks good to me, however there's a couple of changes I think we need to do:

  1. Relevance doesn't make much sense when we're not in a the "search" page, can we hide the relevance option when we're not in the search page?
  2. Similarly, I think we should change the getBookmarks endpoint to not accept relevance as one of its sort orders.

@thiswillbeyourgithub
Copy link
Contributor

Hi,

Can I ask why we can't choose the sort order when querying from the API? I can imagine uses for it.

@MohamedBassem
Copy link
Collaborator

@thiswillbeyourgithub it's an oversight, if you send a PR, I'll happily accept it :)

@thiswillbeyourgithub
Copy link
Contributor

Thanks for the quick reply. Unfortunately I'm useless at typescript (although Karakeep is a good reason for me to focus more on it!) so I just want to explicitely state that I won't make a PR (i.e. don't wait for me).
If @xuatz doesn't either then I'll create a separate issue to track this feature request.

@xuatz
Copy link
Collaborator Author

xuatz commented May 11, 2025

Thanks for the quick reply. Unfortunately I'm useless at typescript (although Karakeep is a good reason for me to focus more on it!) so I just want to explicitely state that I won't make a PR (i.e. don't wait for me).
If @xuatz doesn't either then I'll create a separate issue to track this feature request.

If it's okay to slightly bloat the PR scope I can include it here!

@xuatz
Copy link
Collaborator Author

xuatz commented May 11, 2025

Thanks for the quick reply. Unfortunately I'm useless at typescript (although Karakeep is a good reason for me to focus more on it!) so I just want to explicitely state that I won't make a PR (i.e. don't wait for me).
If @xuatz doesn't either then I'll create a separate issue to track this feature request.

If it's okay to slightly bloat the PR scope I can include it here!

@thiswillbeyourgithub actually, i change my mind. it involves updating the openapi docs at which I'm not opposed to, but i'm not familiar with. i'll do it in a separate PR.

@xuatz
Copy link
Collaborator Author

xuatz commented May 11, 2025

Hey, that was fast @xuatz!

Overall, the PR looks good to me, however there's a couple of changes I think we need to do:

  1. Relevance doesn't make much sense when we're not in a the "search" page, can we hide the relevance option when we're not in the search page?
  2. Similarly, I think we should change the getBookmarks endpoint to not accept relevance as one of its sort orders.

@MohamedBassem

for point number 2, I initially went for the approach to make 2 zSortOrders

const zSearchBookmarksSortOrder = z.enum(["asc", "desc", "relevance"]);
const zGetBookmarksSortOrder = z.enum(["asc", "desc"]);

export type ZSortOrder = z.infer<typeof zSearchBookmarksSortOrder>;

But because they both share the same useSortOrderStore(), getBookmarks() is gonna complain that we are potentially giving it relevance.

I guess we can make 2 stores, one specifically for /search and the existing one for the rest, but I got a feeling we probably don't want that.

Instead I've added a cleanup useEffect in SortOrderToggle.tsx, to reset the sort order, if the page is not /search and if the sortOrder is still "relevance"

  // also see related on page enter sortOrder.relevance init
  // in apps/web/app/dashboard/search/page.tsx
  useEffect(() => {
    if (!isDashboardSearchPage && currentSort === "relevance") {
      // reset to default sort order
      setSortOrder("desc");
    }
  }, [isDashboardSearchPage, currentSort]);

Hard to say which approach you prefer, or if you have a 3rd idea, let me know 👍

@xuatz xuatz requested a review from MohamedBassem May 11, 2025 22:56
@MohamedBassem MohamedBassem merged commit dbd0fd1 into karakeep-app:main May 18, 2025
5 checks passed
@MohamedBassem
Copy link
Collaborator

Thanks a lot @xuatz!

MohamedBassem added a commit to xuatz/karakeep that referenced this pull request May 18, 2025
* fix(search): add new relevance sort order

* address pr comments

* some minor fixes

---------

Co-authored-by: Mohamed Bassem <me@mbassem.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

‘Newest First’ sorting does not work when search is active
3 participants