Skip to content

Adds value-ranking support to result ordering - #869

Closed
djperrefort wants to merge 7 commits into
mainfrom
order_rank
Closed

Adds value-ranking support to result ordering#869
djperrefort wants to merge 7 commits into
mainfrom
order_rank

Conversation

@djperrefort

Copy link
Copy Markdown
Member

This PR introduces a DRF ordering backend called PrecedenceOrderingBackend that extends the default ordering behavior with an optional _rank query parameter. Clients continue to sort with the standard _order parameter, 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 _order reversing the result. A field named in _order without a matching _rank falls back to its natural column order. In keeping with current API standards, malformed _rank terms are silently ignored. Because the backend inherits from DRF's OrderingFilter, it reuses the existing field-validation and default-ordering logic, honors the ORDERING_PARAM setting, and self-documents both parameters in the generated OpenAPI schema. Full unit test coverage is included for parsing, ranking, ordering behavior, and schema generation.

@djperrefort
djperrefort marked this pull request as draft July 13, 2026 19:29
@djperrefort

Copy link
Copy Markdown
Member Author

This was a fun exercise, but is ultimately overengineered for the projects needs. Closing.

@djperrefort
djperrefort deleted the order_rank branch July 23, 2026 18:41
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.

1 participant