1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Closes #10560: New global search (#10676)

* Initial work on new search backend

* Clean up search backends

* Return only the most relevant result per object

* Clear any pre-existing cached entries on cache()

* #6003: Implement global search functionality for custom field values

* Tweak field weights & document guidance

* Extend search() to accept a lookup type

* Move get_registry() out of SearchBackend

* Enforce object permissions when returning search results

* Add indexers for remaining models

* Avoid calling remove() on non-cacheable objects

* Use new search backend by default

* Extend search backend to filter by object type

* Clean up search view form

* Enable specifying lookup logic

* Add indexes for value field

* Remove object type selector from search bar

* Introduce SearchTable and enable HTMX for results

* Enable pagination

* Remove legacy search backend

* Cleanup

* Use a UUID for CachedValue primary key

* Refactoring search methods

* Define max search results limit

* Extend reindex command to support specifying particular models

* Add clear() and size to SearchBackend

* Optimize bulk caching performance

* Highlight matched portion of field value

* Performance improvements for reindexing

* Started on search tests

* Cleanup & docs

* Documentation updates

* Clean up SearchIndex

* Flatten search registry to register by app_label.model_name

* Clean up search backend classes

* Clean up RestrictedGenericForeignKey and RestrictedPrefetch

* Resolve migrations conflict
This commit is contained in:
Jeremy Stretch
2022-10-21 13:16:16 -04:00
committed by GitHub
parent 5d56d95fda
commit 9628dead07
50 changed files with 1579 additions and 675 deletions

View File

@@ -1,7 +1,6 @@
{# Base layout for the core NetBox UI w/navbar and page content #}
{% extends 'base/base.html' %}
{% load helpers %}
{% load search %}
{% load static %}
{% comment %}
@@ -41,7 +40,7 @@ Blocks:
</button>
</div>
<div class="d-flex my-1 flex-grow-1 justify-content-center w-100">
{% search_options request %}
{% include 'inc/searchbar.html' %}
</div>
</div>
@@ -53,7 +52,7 @@ Blocks:
{# Search bar #}
<div class="col-6 d-flex flex-grow-1 justify-content-center">
{% search_options request %}
{% include 'inc/searchbar.html' %}
</div>
{# Proflie/login button #}

View File

@@ -39,13 +39,23 @@
<td>{% checkmark object.required %}</td>
</tr>
<tr>
<th scope="row">Weight</th>
<td>{{ object.weight }}</td>
<th scope="row">Search Weight</th>
<td>
{% if object.search_weight %}
{{ object.search_weight }}
{% else %}
<span class="text-muted">Disabled</span>
{% endif %}
</td>
</tr>
<tr>
<th scope="row">Filter Logic</th>
<td>{{ object.get_filter_logic_display }}</td>
</tr>
<tr>
<th scope="row">Display Weight</th>
<td>{{ object.weight }}</td>
</tr>
<tr>
<th scope="row">UI Visibility</th>
<td>{{ object.get_ui_visibility_display }}</td>

View File

@@ -0,0 +1,6 @@
<form class="input-group" action="{% url 'search' %}" method="get">
<input name="q" type="text" aria-label="Search" placeholder="Search" class="form-control" />
<button class="btn btn-primary" type="submit">
<i class="mdi mdi-magnify"></i>
</button>
</form>

View File

@@ -15,74 +15,24 @@
</ul>
{% endblock tabs %}
{% block content-wrapper %}
<div class="tab-content">
{% if request.GET.q %}
{% if results %}
<div class="row">
<div class="col col-md-9">
{% for obj_type in results %}
<div class="card">
<h5 class="card-header" id="{{ obj_type.name|lower }}">{{ obj_type.name|bettertitle }}</h5>
<div class="card-body table-responsive">
{% render_table obj_type.table 'inc/table.html' %}
</div>
<div class="card-footer text-end">
<a href="{{ obj_type.url }}" class="btn btn-sm btn-primary my-1">
<i class="mdi mdi-arrow-right-bold" aria-hidden="true"></i>
{% if obj_type.table.page.has_next %}
See All {{ obj_type.table.page.paginator.count }} Results
{% else %}
Refine Search
{% endif %}
</a>
</div>
</div>
{% endfor %}
</div>
<div class="col col-md-3">
<div class="card">
<h5 class="card-header">
Search Results
</h5>
<div class="card-body">
<div class="list-group list-group-flush">
{% for obj_type in results %}
<a href="#{{ obj_type.name|lower }}" class="list-group-item">
<div class="float-end">
{% badge obj_type.table.page.paginator.count %}
</div>
{{ obj_type.name|bettertitle }}
</a>
{% endfor %}
</div>
</div>
</div>
</div>
</div>
{% else %}
<h3 class="text-muted text-center">No results found</h3>
{% endif %}
{% else %}
<div class="row">
<div class="col col-12 col-lg-6 offset-lg-3">
<form action="{% url 'search' %}" method="get" class="form form-horizontal">
<div class="card">
<h5 class="card-header">
Search
</h5>
<div class="card-body">
{% render_form form %}
</div>
<div class="card-footer text-end">
<button type="submit" class="btn btn-primary">
<span class="mdi mdi-magnify" aria-hidden="true"></span> Search
</button>
</div>
</div>
</form>
</div>
{% block content %}
<div class="row px-3">
<div class="col col-6 offset-3 py-3">
<form action="{% url 'search' %}" method="get" class="form form-horizontal">
{% render_form form %}
<div class="text-end">
<button type="submit" class="btn btn-primary">
<span class="mdi mdi-magnify" aria-hidden="true"></span> Search
</button>
</div>
{% endif %}
</form>
</div>
</div>
{% endblock content-wrapper %}
<div class="row px-3">
<div class="card">
<div class="card-body" id="object_list">
{% include 'htmx/table.html' %}
</div>
</div>
</div>
{% endblock content %}