[PR #11686] [MERGED] Fixes #11685 - Include containing prefixes and aggregates when searching for IP addresses #13823

Closed
opened 2025-12-29 23:21:00 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/11686
Author: @kkthxbye-code
Created: 2/7/2023
Status: Merged
Merged: 2/20/2023
Merged by: @jeremystretch

Base: developHead: poc-ip-search


📝 Commits (6)

  • 111dbef Proof of concept for showing containing prefixes when searching for ip-addresses.
  • e93f592 Fix typo in search query
  • 0b998a6 Create CachedValueField to contain search specific lookups
  • 6c20eca pep8 fixes
  • 2a43672 Address feedback
  • 226599f Change Prefix and Aggregate search index weights to better order search results.

📊 Changes

7 files changed (+71 additions, -13 deletions)

View changed files

netbox/extras/fields.py (+8 -0)
📝 netbox/extras/lookups.py (+16 -1)
netbox/extras/migrations/0085_change_cachedvalue_value_type.py (+19 -0)
📝 netbox/extras/models/search.py (+2 -1)
📝 netbox/ipam/search.py (+2 -2)
📝 netbox/netbox/search/__init__.py (+7 -0)
📝 netbox/netbox/search/backends.py (+17 -9)

📄 Description

Fixes: #11685

  • Changes the CachedValue types of IPAddressField and IPNetworkField to inet and cidr.
  • Creates a child class of TextField called CachedValueField (not sure about the name). Reasoning as discussed on slack is to prevent adding special lookup types to the global TextField field.
  • A NetContainsOrEquals lookup has been added to CachedValueField which casts the string value to inet and does a >>= lookup on it.
  • Changing the type create a new migration, however as far as I can tell, it's pretty much a NOP migration, there should be no change to the database schema. Not sure if this is preventable.
  • If the search query in partial mode parses as a IP address, all CachedValues of type cidr are queried to check if they contain the IP being searched for.

There's some screenshots here: https://github.com/netbox-community/netbox/discussions/11665#discussioncomment-4882273

There's still time to evaluate if we want to do something special about searching for inet type fields (IPAddresses), which we can handle in this PR or later.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/11686 **Author:** [@kkthxbye-code](https://github.com/kkthxbye-code) **Created:** 2/7/2023 **Status:** ✅ Merged **Merged:** 2/20/2023 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `develop` ← **Head:** `poc-ip-search` --- ### 📝 Commits (6) - [`111dbef`](https://github.com/netbox-community/netbox/commit/111dbefe83b6e7501941b272d850687c6ab7ef7d) Proof of concept for showing containing prefixes when searching for ip-addresses. - [`e93f592`](https://github.com/netbox-community/netbox/commit/e93f592e657165727ea522aa782c7e5cad9afc86) Fix typo in search query - [`0b998a6`](https://github.com/netbox-community/netbox/commit/0b998a652a28b2e929e2f2b6df679ad9ae8a7ec6) Create CachedValueField to contain search specific lookups - [`6c20eca`](https://github.com/netbox-community/netbox/commit/6c20eca594531fcc9511bd819455d250196c6a20) pep8 fixes - [`2a43672`](https://github.com/netbox-community/netbox/commit/2a43672dfc2f47576cbc7d80e252fd0cd74167c2) Address feedback - [`226599f`](https://github.com/netbox-community/netbox/commit/226599f66e930d685d2dd24f6ab6691170437ece) Change Prefix and Aggregate search index weights to better order search results. ### 📊 Changes **7 files changed** (+71 additions, -13 deletions) <details> <summary>View changed files</summary> ➕ `netbox/extras/fields.py` (+8 -0) 📝 `netbox/extras/lookups.py` (+16 -1) ➕ `netbox/extras/migrations/0085_change_cachedvalue_value_type.py` (+19 -0) 📝 `netbox/extras/models/search.py` (+2 -1) 📝 `netbox/ipam/search.py` (+2 -2) 📝 `netbox/netbox/search/__init__.py` (+7 -0) 📝 `netbox/netbox/search/backends.py` (+17 -9) </details> ### 📄 Description ### Fixes: #11685 * Changes the CachedValue types of IPAddressField and IPNetworkField to `inet` and `cidr`. * Creates a child class of TextField called CachedValueField (not sure about the name). Reasoning as discussed on slack is to prevent adding special lookup types to the global TextField field. * A NetContainsOrEquals lookup has been added to CachedValueField which casts the string value to inet and does a >>= lookup on it. * Changing the type create a new migration, however as far as I can tell, it's pretty much a NOP migration, there should be no change to the database schema. Not sure if this is preventable. * If the search query in partial mode parses as a IP address, all CachedValues of type `cidr` are queried to check if they contain the IP being searched for. There's some screenshots here: https://github.com/netbox-community/netbox/discussions/11665#discussioncomment-4882273 There's still time to evaluate if we want to do something special about searching for `inet` type fields (IPAddresses), which we can handle in this PR or later. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-29 23:21:00 +01:00
adam closed this issue 2025-12-29 23:21:00 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#13823