Skip to content

Order global search results by value of matched fields #14035

@jeremystretch

Description

@jeremystretch

NetBox version

v3.6.3

Feature type

Change to existing functionality

Proposed functionality

When returning global search results, order results of equal precedence and object type by value. This should ensure that otherwise equally-relevant results appear in a human-friendly order.

The current ordering for cached search result objects is:

class CachedValue:
    class Meta:
        ordering = ('weight', 'object_type', 'object_id')

This FR would modify the above to:

class CachedValue:
    class Meta:
        ordering = ('weight', 'object_type', 'value', 'object_id')

(object_id is retained as a tie-breaker for results having the same matched value, to ensure deterministic ordering.)

Use case

This adjustment serves to ensure otherwise equally-relevant search results are listed in a human-friendly order. (This was first raised as a bug report under #13940.)

Database changes

This will require a model migration to effect the new default ordering for CachedValue.

External dependencies

None

Metadata

Metadata

Assignees

Labels

status: acceptedThis issue has been accepted for implementationtype: featureIntroduction of new functionality to the application

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions