-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
Implement "Random" as a sorting option, add standalone "Random" page #109
Conversation
…for entire collection.
Thank you ! That looks cool. |
Awesome! I just pushed a small change to remove the pagination from the Random page--a single set is all that's needed as it randomly regenerates every reload. |
@@ -90,6 +94,18 @@ fun formatLike(input: String): String { | |||
return "%$input%" | |||
} | |||
|
|||
// Implement function for SQL RANDOM() | |||
object RandomOrder : Function<Long>(LongColumnType()) { | |||
override fun toQueryBuilder(queryBuilder: QueryBuilder) = queryBuilder { append("RANDOM()") } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry I suck at sql, where does the random() function comes from ?
Is it sqlite random() ? https://www.sqlite.org/lang_corefunc.html#random
Does it work well with the Exposed framework ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your question prompted me to revisit my research. The documentation/threads I found called out that RANDOM had to implemented via direct SQL command. Since then, there's actually a Random class available in Exposed. I've pushed changes to adopt this instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok that looks cool, I'll have a deeper look later. Thank you for looking into this.
The PageSort result length didn't update the pagination length in the UI anyways.
I further reverted the |
We will need tests for the backend here as well. |
I'm curious -- how would you propose that? We'd need to populate the test harness DB with multiple books and can query them, but there's always the risk that two concurrent requests return the same result set/order (especially if there's a small number of results). I'm happy to implement something, but testing a Random sortby will require a lot more standup and there is always that chance. I can't think of anything that wouldn't be mitigating a low chance that the test fails -- which will always be there. |
For this use case I would go for the sanity check rather than testing that we actually get random results. |
That's reasonable -- I'll look to mock that in tonight. |
Validated Random appropriately limits to pageSize as well.
Alright, tests are up! |
## [0.56.0](v0.55.0...v0.56.0) (2024-04-29) ### Features * add Random page and random sorting option ([#109](#109)) ([186f8f0](186f8f0))
🎉 This PR is included in version 0.56.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Inspired by the "Random" page segment in Calibre-Web, I really enjoy rediscovering items in my list randomly. To that end, this PR implements "Random" sort.
parseSort
method and directly apply the sort order