w3c-api icon indicating copy to clipboard operation
w3c-api copied to clipboard

Sort lists of items sensibly before returning them (?)

Open tripu opened this issue 8 years ago • 9 comments

How difficult would it be on the API backend [or, would it make sense] to sort lists of items by some relevant field? Right now, some lists are sorted according to some kind of useful order; others look shuffled.

Specifically:

There may be others (I'll add here if I find them).

Most clients I can think of will have to sort those lists themselves anyway. (That's the case with Apiary and Unitas, at least.) Doesn't it make more sense to sort them on the server before returning them?

tripu avatar Dec 17 '16 18:12 tripu

https://api.w3.org/functions seems ordered by IDs; not numerically but lexicographically.

I suggest order by title instead.

tripu avatar Feb 03 '17 17:02 tripu

https://api.w3.org/groups/55181/participations?embed=true seems also sorted by numeric ID, but lexicographically (eg, 10 < 9), which is of little use.

tripu avatar Feb 07 '17 09:02 tripu

Actually, there is no sorting at all except for the ones you listed as sorted by family name (which is actually not intentional but comes from a piece of code that does it but shouldn't (IMO)).

My first thought is that sorting should be done client-side, but this is flawed since you couldn't sort paginated results (unless you first retrieved all pages) so I think it is a good idea to add a server-side sorting feature, configurable through the query string. I am not sure how difficult this will be and how long it will take to implement.

jean-gui avatar Feb 09 '17 10:02 jean-gui

I have a vested interest in having human-friendly sorting implemented server-side (for my API clients). But, to be honest, pagination doesn't need friendly sorting — it just needs to be deterministic, predictable.

For example, you could sort everything, always, by the SHA-1 checksum of their primary key, and paginated queries to the API would always return the same results, in the same order. I think that's the only thing that matters to keep consistency on the clients. If a client needs a different order, it should retrieve all pages first, then sort the whole set itself.

That being said… :+1: to sorting sensibly on the server by default, or by passing additional parameters in the request! It'll save me some work! :smile:

tripu avatar Feb 09 '17 10:02 tripu

My apologies, I wasn't clear at all. The way lists are sorted is deterministic, it's just that they are sorted in the order rows were entered in the database. In SQL, if you run "SELECT * from foo;" you will always get results in the same order, it's just usually not any useful order.

jean-gui avatar Feb 09 '17 11:02 jean-gui

@jean-gui: OK, understood. I'll wait for you guys to evaluate this feature request, then.

tripu avatar Feb 10 '17 16:02 tripu

So, is it on the road map to sort vectors sensibly before serving them, or shall I start implementing that on my clients…?

tripu avatar Oct 19 '17 15:10 tripu

Unfortunately, I don't have time to work on that feature.

jean-gui avatar Oct 20 '17 13:10 jean-gui

Understood, @jean-gui!

tripu avatar Oct 20 '17 13:10 tripu