From 14858dd79078d2d1d998217fb1abec5165fed0a6 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Wed, 12 Oct 2022 11:36:26 -0400 Subject: [PATCH] Tweak field weights & document guidance --- docs/development/search.md | 16 ++++++++++++++++ mkdocs.yml | 1 + netbox/circuits/search.py | 8 ++++---- netbox/dcim/search.py | 26 +++++++++++++------------- netbox/extras/search.py | 2 +- netbox/tenancy/search.py | 14 +++++++------- netbox/virtualization/search.py | 4 ++-- netbox/wireless/search.py | 4 ++-- 8 files changed, 46 insertions(+), 29 deletions(-) create mode 100644 docs/development/search.md diff --git a/docs/development/search.md b/docs/development/search.md new file mode 100644 index 000000000..27730a6f5 --- /dev/null +++ b/docs/development/search.md @@ -0,0 +1,16 @@ +# Search + +## Field Weight Guidance + +| Weight | Field Role | Examples | +|--------|--------------------------------------------------|----------------------------------------------------| +| 50 | Unique serialized attribute | Device.asset_tag | +| 60 | Unique serialized attribute (per related object) | Device.serial | +| 100 | Primary human identifier | Device.name, Circuit.cid, Cable.label | +| 110 | Slug | Site.slug | +| 200 | Secondary identifier | Provider.account, DeviceType.part_number | +| 300 | Highly unique descriptive attribute | CircuitTermination.xconnect_id, IPAddress.dns_name | +| 500 | Description | Site.description | +| 1000 | Custom field default | - | +| 2000 | Other discrete attribute | CircuitTermination.port_speed | +| 5000 | Comment field | Site.comments | diff --git a/mkdocs.yml b/mkdocs.yml index fc3a40632..011d4414f 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -245,6 +245,7 @@ nav: - Adding Models: 'development/adding-models.md' - Extending Models: 'development/extending-models.md' - Signals: 'development/signals.md' + - Search: 'development/search.md' - Application Registry: 'development/application-registry.md' - User Preferences: 'development/user-preferences.md' - Web UI: 'development/web-ui.md' diff --git a/netbox/circuits/search.py b/netbox/circuits/search.py index cdb122cf9..7185043af 100644 --- a/netbox/circuits/search.py +++ b/netbox/circuits/search.py @@ -9,7 +9,7 @@ class CircuitIndex(SearchIndex): fields = ( ('cid', 100), ('description', 500), - ('comments', 1000), + ('comments', 5000), ) queryset = models.Circuit.objects.prefetch_related( 'type', 'provider', 'tenant', 'tenant__group', 'terminations__site' @@ -34,7 +34,7 @@ class CircuitTypeIndex(SearchIndex): model = models.CircuitType fields = ( ('name', 100), - ('slug', 100), + ('slug', 110), ('description', 500), ) @@ -45,7 +45,7 @@ class ProviderIndex(SearchIndex): fields = ( ('name', 100), ('account', 200), - ('comments', 1000), + ('comments', 5000), ) queryset = models.Provider.objects.annotate( count_circuits=count_related(models.Circuit, 'provider') @@ -60,7 +60,7 @@ class ProviderNetworkIndex(SearchIndex): ('name', 100), ('service_id', 200), ('description', 500), - ('comments', 1000), + ('comments', 5000), ) queryset = models.ProviderNetwork.objects.prefetch_related('provider') filterset = filtersets.ProviderNetworkFilterSet diff --git a/netbox/dcim/search.py b/netbox/dcim/search.py index 1216cb82b..838a5a9d9 100644 --- a/netbox/dcim/search.py +++ b/netbox/dcim/search.py @@ -20,7 +20,7 @@ class DeviceIndex(SearchIndex): ('asset_tag', 50), ('serial', 60), ('name', 100), - ('comments', 1000), + ('comments', 5000), ) queryset = models.Device.objects.prefetch_related( 'device_type__manufacturer', @@ -40,7 +40,7 @@ class DeviceRoleIndex(SearchIndex): model = models.DeviceRole fields = ( ('name', 100), - ('slug', 100), + ('slug', 110), ('description', 500), ) @@ -51,7 +51,7 @@ class DeviceTypeIndex(SearchIndex): fields = ( ('model', 100), ('part_number', 200), - ('comments', 1000), + ('comments', 5000), ) queryset = models.DeviceType.objects.prefetch_related('manufacturer').annotate( instance_count=count_related(models.Device, 'device_type') @@ -64,7 +64,7 @@ class LocationIndex(SearchIndex): model = models.Location fields = ( ('name', 100), - ('slug', 100), + ('slug', 110), ('description', 500), ) queryset = models.Location.objects.add_related_count( @@ -85,7 +85,7 @@ class ModuleIndex(SearchIndex): fields = ( ('asset_tag', 50), ('serial', 60), - ('comments', 1000), + ('comments', 5000), ) queryset = models.Module.objects.prefetch_related( 'module_type__manufacturer', @@ -101,7 +101,7 @@ class ModuleTypeIndex(SearchIndex): fields = ( ('model', 100), ('part_number', 200), - ('comments', 1000), + ('comments', 5000), ) queryset = models.ModuleType.objects.prefetch_related('manufacturer').annotate( instance_count=count_related(models.Module, 'module_type') @@ -114,7 +114,7 @@ class PowerFeedIndex(SearchIndex): model = models.PowerFeed fields = ( ('name', 100), - ('comments', 1000), + ('comments', 5000), ) queryset = models.PowerFeed.objects.all() filterset = filtersets.PowerFeedFilterSet @@ -127,8 +127,8 @@ class RackIndex(SearchIndex): ('asset_tag', 50), ('serial', 60), ('name', 100), - ('facility_id', 100), - ('comments', 1000), + ('facility_id', 200), + ('comments', 5000), ) queryset = models.Rack.objects.prefetch_related('site', 'location', 'tenant', 'tenant__group', 'role').annotate( device_count=count_related(models.Device, 'rack') @@ -151,7 +151,7 @@ class RegionIndex(SearchIndex): model = models.Region fields = ( ('name', 100), - ('slug', 100), + ('slug', 110), ('description', 500) ) @@ -163,8 +163,8 @@ class SiteIndex(SearchIndex): ('name', 100), ('facility', 100), ('description', 500), - ('physical_address', 1000), - ('shipping_address', 1000), + ('physical_address', 2000), + ('shipping_address', 2000), ) queryset = models.Site.objects.prefetch_related('region', 'tenant', 'tenant__group') filterset = filtersets.SiteFilterSet @@ -175,7 +175,7 @@ class SiteGroupIndex(SearchIndex): model = models.SiteGroup fields = ( ('name', 100), - ('slug', 100), + ('slug', 110), ('description', 500) ) diff --git a/netbox/extras/search.py b/netbox/extras/search.py index ab2e3787d..7eea11273 100644 --- a/netbox/extras/search.py +++ b/netbox/extras/search.py @@ -8,7 +8,7 @@ from netbox.search import SearchIndex, register_search class JournalEntryIndex(SearchIndex): model = JournalEntry fields = ( - ('comments', 1000), + ('comments', 5000), ) queryset = JournalEntry.objects.prefetch_related('assigned_object', 'created_by') filterset = extras.filtersets.JournalEntryFilterSet diff --git a/netbox/tenancy/search.py b/netbox/tenancy/search.py index e00f6d933..a7496460b 100644 --- a/netbox/tenancy/search.py +++ b/netbox/tenancy/search.py @@ -10,12 +10,12 @@ class ContactIndex(SearchIndex): model = Contact fields = ( ('name', 100), - ('title', 200), - ('phone', 200), - ('email', 200), - ('address', 200), + ('title', 300), + ('phone', 300), + ('email', 300), + ('address', 300), ('link', 300), - ('comments', 1000), + ('comments', 5000), ) queryset = Contact.objects.prefetch_related('group', 'assignments').annotate( assignment_count=count_related(ContactAssignment, 'contact') @@ -28,9 +28,9 @@ class TenantIndex(SearchIndex): model = Tenant fields = ( ('name', 100), - ('slug', 100), + ('slug', 110), ('description', 500), - ('comments', 1000), + ('comments', 5000), ) queryset = Tenant.objects.prefetch_related('group') filterset = tenancy.filtersets.TenantFilterSet diff --git a/netbox/virtualization/search.py b/netbox/virtualization/search.py index 25c3ee647..7936ad476 100644 --- a/netbox/virtualization/search.py +++ b/netbox/virtualization/search.py @@ -11,7 +11,7 @@ class ClusterIndex(SearchIndex): model = Cluster fields = ( ('name', 100), - ('comments', 1000), + ('comments', 5000), ) queryset = Cluster.objects.prefetch_related('type', 'group').annotate( device_count=count_related(Device, 'cluster'), vm_count=count_related(VirtualMachine, 'cluster') @@ -24,7 +24,7 @@ class VirtualMachineIndex(SearchIndex): model = VirtualMachine fields = ( ('name', 100), - ('comments', 1000), + ('comments', 5000), ) queryset = VirtualMachine.objects.prefetch_related( 'cluster', diff --git a/netbox/wireless/search.py b/netbox/wireless/search.py index 151aff694..4b6d2c457 100644 --- a/netbox/wireless/search.py +++ b/netbox/wireless/search.py @@ -12,7 +12,7 @@ class WirelessLANIndex(SearchIndex): fields = ( ('ssid', 100), ('description', 500), - ('auth_psk', 1000), + ('auth_psk', 2000), ) queryset = WirelessLAN.objects.prefetch_related('group', 'vlan').annotate( interface_count=count_related(Interface, 'wireless_lans') @@ -26,7 +26,7 @@ class WirelessLinkIndex(SearchIndex): fields = ( ('ssid', 100), ('description', 500), - ('auth_psk', 1000), + ('auth_psk', 2000), ) queryset = WirelessLink.objects.prefetch_related('interface_a__device', 'interface_b__device') filterset = wireless.filtersets.WirelessLinkFilterSet