Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable PostgreSQL full text searching #7016

Closed
jeremystretch opened this issue Aug 23, 2021 · 13 comments
Closed

Enable PostgreSQL full text searching #7016

jeremystretch opened this issue Aug 23, 2021 · 13 comments
Labels
type: feature Introduction of new functionality to the application

Comments

@jeremystretch
Copy link
Member

NetBox version

v2.11.11

Feature type

New functionality

Proposed functionality

Extend NetBox's search functionality to employ PostgreSQL's native full text search capability. This is already supported by Django: https://docs.djangoproject.com/en/3.2/ref/contrib/postgres/search/

I haven't dug into this too much yet, but it appears to be pretty straightforward. I expect the bulk of the work will involve replacing our sets of filter() parameters with SearchQuery and SearchVector instances, and adding a common SearchVectorField to all appropriate models.

I'm also open to alternative strategies for improving NetBox's global search performance, however any such proposals should be opened as separate feature requests and referenced here.

Use case

This change should provide much more robust search functionality, and allow us to rank search results according to customizable rankings per model.

Database changes

We'll likely need to add a new SearchVectorField to each searchable model.

External dependencies

No response

@jeremystretch jeremystretch added type: feature Introduction of new functionality to the application status: under review Further discussion is needed to determine this issue's scope and/or implementation labels Aug 23, 2021
@jeremystretch jeremystretch added needs milestone Awaiting prioritization for inclusion with a future NetBox release and removed status: under review Further discussion is needed to determine this issue's scope and/or implementation labels Oct 5, 2021
@samschmitt22
Copy link

Would this enable global searching based off of any object fields? That would be a great feature to have to find things that we might not know the name of 100%

@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation and removed needs milestone Awaiting prioritization for inclusion with a future NetBox release labels Dec 15, 2021
@jeremystretch jeremystretch added this to the v3.3 milestone Dec 15, 2021
@ghost
Copy link

ghost commented Jan 3, 2022

Would this enable global searching based off of any object fields? That would be a great feature to have to find things that we might not know the name of 100%

Including MAC addresses. :-)

@hagbarddenstore
Copy link
Contributor

From the plugin framework workgroup:

Be able to add models defined in plugins to the global / full text search capabilities mentioned here.

@PieterL75
Copy link
Contributor

Looking forward to v3.3 with this full-text search !

@jeremystretch
Copy link
Member Author

Unfortunately it doesn't look like we'll be able to tackle this in v3.3 without additional help. A lot of work is still needed to determine exactly how this should be implemented, and any overlap with a future indexer (yet to be determined) must be evaluated.

@jeremystretch jeremystretch added status: under review Further discussion is needed to determine this issue's scope and/or implementation and removed status: accepted This issue has been accepted for implementation labels Jun 2, 2022
@jeremystretch jeremystretch removed this from the v3.3 milestone Jun 2, 2022
@PieterL75
Copy link
Contributor

Is there a way to introduce a wildcard in the search as an alternative? So that we can do switch00 or devsw ?
This is really one of the biggest remarks I get from new users that migrate from our old cmdb

@github-actions
Copy link
Contributor

github-actions bot commented Aug 2, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Do not attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our contributing guide.

@github-actions github-actions bot added the pending closure Requires immediate attention to avoid being closed for inactivity label Aug 2, 2022
@ITJamie
Copy link
Contributor

ITJamie commented Aug 10, 2022

Would it be possible to sponsor this as a feature?

@jeremystretch
Copy link
Member Author

@ITJamie we don't allow direct sponsorship of features in NetBox, however you're certainly welcome to compensate individuals who want to help explore the feasibility of this proposal and perhaps develop a proof of concept.

@jeremystretch jeremystretch removed the pending closure Requires immediate attention to avoid being closed for inactivity label Aug 11, 2022
@arthanson arthanson self-assigned this Aug 25, 2022
@arthanson
Copy link
Collaborator

Dug into this more:

  1. watson - is tailored to a title-description-content search which I'm not sure really maps to what NetBox needs. But does offer a multi-model search and does a lot of the work for you.
  2. Django Postgres search - more flexible, would need to replicate some of what watson is doing, also watson probably would be easier for plugin search unless we replicate some of the model-registration stuff (probably a good idea).
  3. Current NetBox search does partial word match (icontains) so if you search "kron" it will match "Akron" - postgresql search (and watson) can only do prefix search (so only startswith) it won't find a partial string embedded in another. So this would potentially break functionality that someone might use?
  4. Doing things like searching device by ipaddress is doable, we just need to explicitly define these as searchable combos. PostgreSQL search we would need to specifically define them, watson looks like you have a middleware that would follow the FK but bloating out the search index.
  5. Watson would be quicker to implement but less adaptable and might not be a perfect fit. PostgreSQL would require more work (replicating some of watson stuff).
  6. Trigram stuff would allow embedded character search, similar search, etc... but requires the PostgreSQL extension so is probably a no-go.
  7. Also can make it do "ipam:xxx" to search a specific model type, also found stuff to do more complicated google type searches if needed (- to exclude stuff, and or queries, etc...)

@DanSheps
Copy link
Member

  • Current NetBox search does partial word match (icontains) so if you search "kron" it will match "Akron" - postgresql search (and watson) can only do prefix search (so only startswith) it won't find a partial string embedded in another. So this would potentially break functionality that someone might use?

I suspect we would want to find a way to keep icontains, as I imagine a lot of people rely on it.

@arthanson arthanson added this to the v3.4 milestone Sep 16, 2022
arthanson added a commit that referenced this issue Sep 19, 2022
@jeremystretch jeremystretch added status: blocked Another issue or external requirement is preventing implementation and removed status: under review Further discussion is needed to determine this issue's scope and/or implementation labels Sep 27, 2022
@jeremystretch
Copy link
Member Author

jeremystretch commented Sep 27, 2022

Marking this as temporarily blocked by #8927. At this point we still intend to implement this for v3.4.

@jeremystretch
Copy link
Member Author

I'm going to close this out in favor of an alternate implementation detailed in #10560, which I expect to be considerably more robust. This issue will be retained for reference in the event the other proposal proves untenable.

@jeremystretch jeremystretch closed this as not planned Won't fix, can't repro, duplicate, stale Oct 4, 2022
@jeremystretch jeremystretch removed the status: blocked Another issue or external requirement is preventing implementation label Oct 4, 2022
jeremystretch pushed a commit that referenced this issue Oct 10, 2022
jeremystretch added a commit that referenced this issue Oct 10, 2022
* #7016 base search classes

* 7016 add search indexes

* 7016 add search indexes

* 7016 add search indexes

* 7016 add search indexes

* 7016 add search indexes

* 7016 add search indexes

* 8927 refactor search

* 8927 refactor search

* 8927 refactor search

* 8927 refactor search

* 8927 get search choices working

* 8927 cleanup - optimize

* 8927 use backend search function

* 8927 fix for plugin search

* 8927 add docs

* Move search app to a module under netbox/

* Utilize global registry to register model search classes

* Build search form options from registry

* Determine search categories from model app by default

* Enable dynamic search registration for plugins

* Update docs & improve plugin support

* Clean up search backend class

* Docs for #8927

Co-authored-by: jeremystretch <[email protected]>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: feature Introduction of new functionality to the application
Projects
None yet
Development

No branches or pull requests

7 participants