openlibrary icon indicating copy to clipboard operation
openlibrary copied to clipboard

Work series - Collections are listed in reverse order

Open popcar2 opened this issue 8 months ago • 7 comments

Problem

Collections are listed in reverse order in work series pages. e.g. book collecting 3-4 is shown before book 1-2.

Image

Reproducing the bug

See https://openlibrary.org/series/OL328989L/Invincible for an example

Context

No context needed

Breakdown

Implementation Details (for maintainers)

Requirements Checklist

  • [ ]

Related files

Stakeholders


Instructions for Contributors

  • Please run these commands to ensure your repository is up to date before creating a new branch to work on this issue and each time after pushing code to Github, because the pre-commit bot may add commits to your PRs upstream.

popcar2 avatar Mar 21 '26 16:03 popcar2

will solve this issue

eshanthh avatar Mar 21 '26 17:03 eshanthh

Hi @eshantharjun9-hub I think the current issue is real, but a simple numeric sort may not fully solve it.

The problem seems to be that the series page is mixing different edition types into one flat list:

  • single volumes
  • collected editions (e.g. 22–23, 24–25)
  • compendiums/omnibuses (e.g. 1–9)

If we sort only by the first number in the range, that may improve collection ordering, but it can also make the main single-volume sequence look worse. For example, a strict “range start” sort could lead to something like:

1 1–3 1–9 2 3

That is technically sortable, but not very reader-friendly for people following the core volume order.

A cleaner solution might be to separate entries by edition type instead of forcing everything into one ordered list.

For example:

Standard Volumes

  • 1
  • 2
  • 3
  • ...

Collected Editions

  • 1–3
  • 4–5
  • 8–9
  • 12–13
  • 22–23
  • 24–25

Compendiums / Omnibuses

  • 1–9

This would preserve the clean reading flow for the main series while still showing bundled editions in a logical way.

If grouping by edition type is too big UI change, another fallback could be:

  1. keep standard single-volume entries in numeric order first
  2. show collected editions after that in numeric range order
  3. show compendiums/omnibuses in their own section or at the end

I think that would be more usable than trying to make one flat sort order satisfy all cases.

What do you think @mekarpeles ?

Harshul23 avatar Mar 21 '26 19:03 Harshul23

Seconding what @Harshul23 said. I asked in Slack on how we should organize collections a few days ago but didn't get a response (I don't think anybody established what to do yet).

It would be great if we can have some way to separate different collections, I'm pretty fond of how LibraryThing does it where the series page is a bunch of separated lists, see https://www.librarything.com/nseries/682/The-Walking-Dead for a really well organized example. You've got paperbacks, hardcover collections, omnibuses etc. all separated. That also allows us to include things like one-offs and specials.

I realize that might be too complicated/out of scope though. If it is, then there should at least be a way to set the order manually so OpenLibrary doesn't automatically mix in different collections together (I'm not aware if you could do this already or not). I know Goodreads does mix in everything in one page so it wouldn't be too weird, see https://www.goodreads.com/series/66423-invincible .

popcar2 avatar Mar 21 '26 19:03 popcar2

Hi, @popcar2 , @eshantharjun9-hub and @Harshul23 ! The discussion on how to sort series is still pending. Series was using the same method as works and lists which was causing some issues and that's why we hid the sorting options. Staff is aware of it and pending on how the approach will be.

IvanPisquiy06 avatar Mar 21 '26 22:03 IvanPisquiy06

Great investigation folks! Hmm, having something like "groups" on the series page would be interesting... If folks want to create a proposal as a separate issue that would be great! (Cc @mheiman ) I reckon it would involve adding a new field to the work-series edge object for "group", with a default of "Main".

For now, to fix the sorting issue here we can take advantage of a trick of the python sorting method.

The sorting currently happens here: https://github.com/internetarchive/openlibrary/blob/88000ee010aa4a33130f5dcb1e0905963c7f73f8/openlibrary/core/lists/model.py#L684-L692

This is converting the position string to a plain float used for sorting with the python sorted method.

But we can also return a tuple! Which allows for much more customised sorting. So we'll likely want to update this method to return:

(
    Literal['A: Numeric', 'B: Non-numeric', 'C: Range'],
    int,  # max - min for a range; otherwise 1
    int,  # the lower value in a range; or the value itself for numeric, or 0
    int,  # the number from the work id as a tie break for consistent ordering
)

That should ensure we get an ordering that:

  • Puts single books first, in order
  • Puts other stuff next
  • Puts collections and compendiums at the end in order, with smaller collections appearing before larger collections
  • Is persistent regardless of what random order the db returns things in

Would you be interested in tackling that @Harshul23 ?

cdrini avatar Mar 24 '26 15:03 cdrini

Yes I’d be interested in tackling this. I’ll take a look at the sorting logic in openlibrary/core/lists/model.py and try implementing the tuple based approach you suggested.

I also agree that the broader "groups" idea probably deserves a separate proposal issue rather than overloading this bug thread.

Harshul23 avatar Mar 24 '26 15:03 Harshul23

Hi @cdrini I’ve completed this and opened a PR with the sorting fix. The implementation updates the series sorting logic to handle numeric, non-numeric, and range-based position values more predictably, and adds a focused test covering the new ordering behavior.

Thanks for the guidance on the tuple-based sort approach. Waiting for your approval.

Harshul23 avatar Mar 24 '26 20:03 Harshul23