Adds value-ranking support to result ordering - #869
Closed
djperrefort wants to merge 7 commits into
Closed
Conversation
djperrefort
marked this pull request as draft
July 13, 2026 19:29
Member
Author
|
This was a fun exercise, but is ultimately overengineered for the projects needs. Closing. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR introduces a DRF ordering backend called
PrecedenceOrderingBackendthat extends the default ordering behavior with an optional_rankquery parameter. Clients continue to sort with the standard_orderparameter, but can now supply an explicit value ranking per field as_rank=field:value1,value2,value3. Rows are ordered by each value's position in the rank list with unranked values sorting last and the-prefix on_orderreversing the result. A field named in_orderwithout a matching_rankfalls back to its natural column order. In keeping with current API standards, malformed_rankterms are silently ignored. Because the backend inherits from DRF'sOrderingFilter, it reuses the existing field-validation and default-ordering logic, honors theORDERING_PARAMsetting, and self-documents both parameters in the generated OpenAPI schema. Full unit test coverage is included for parsing, ranking, ordering behavior, and schema generation.