Skip to content

Commit 132494b

Browse files
authored
Display the list of fields for the advanced search syntax #1164 (#1167)
Signed-off-by: tdruez <tdruez@nexb.com>
1 parent 9aef059 commit 132494b

File tree

3 files changed

+69
-36
lines changed

3 files changed

+69
-36
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ Changelog
44
v34.4.0 (unreleased)
55
--------------------
66

7+
- Display the list of fields available for the advanced search syntax in the modal UI.
8+
https://github.com/nexB/scancode.io/issues/1164
9+
710
- Add support for CycloneDX 1.6 outputs and inputs.
811
Also, the CycloneDX outputs can be downloaded as 1.6, 1.5, and 1.4 spec versions.
12+
https://github.com/nexB/scancode.io/pull/1165
913

1014
v34.3.0 (2024-04-10)
1115
--------------------

scanpipe/templates/scanpipe/modals/search_syntax_modal.html

Lines changed: 57 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,67 @@
22
<div class="modal-background"></div>
33
<div class="modal-card">
44
<header class="modal-card-head">
5-
<p class="modal-card-title">Search syntax</p>
5+
<p class="modal-card-title">Search {{ filter.verbose_name_plural }}</p>
66
<button class="delete" aria-label="close"></button>
77
</header>
8-
<section class="modal-card-body px-2">
8+
<div class="modal-card-body p-2 pb-4">
99
<div class="content">
10-
<ul class="mt-0">
11-
<li>
12-
<strong>Single Term:</strong> Enter a single word to search for exact matches.<br>
13-
Example: <code>file.txt</code>
14-
</li>
15-
<li>
16-
<strong>Quoted Phrases:</strong> Use double quotes to search for exact phrases.<br>
17-
Example: <code>"name version"</code>
18-
</li>
19-
<li>
20-
<strong>Field Searches:</strong> Specify fields to narrow down your search.<br>
21-
Use <code>field_name:</code> followed by your search term.<br>
22-
Example: <code>name:file.txt</code></li>
23-
<li>
24-
<strong>Negation:</strong> Use a hyphen (-) before a field name to exclude results.<br>
25-
Example: <code>-name:file.txt</code></li>
26-
<li>
27-
<strong>Lookup Types:</strong> Use lookup types to perform specific searches.
28-
<ul>
29-
<li><code>=</code>: Exact match</li>
30-
<li><code>^</code>: Starts with</li>
31-
<li><code>$</code>: Ends with</li>
32-
<li><code>~</code>: Contains</li>
33-
<li><code>&gt;</code>: Greater than</li>
34-
<li><code>&lt;</code>: Less than</li>
35-
</ul>
36-
Example: <code>path^:dir1</code>
37-
</li>
38-
<li>
39-
<strong>Multiple queries</strong> are combined with the <code>AND</code> operator.<br>
40-
Example: <code>name:file.txt status:scanned</code>
41-
</li>
42-
</ul>
10+
<div class="tabs is-boxed mb-4">
11+
<ul class="m-0">
12+
<li class="is-active">
13+
<a data-target="tab-syntax" >Syntax</a>
14+
</li>
15+
<li>
16+
<a data-target="tab-fields">Fields</a>
17+
</li>
18+
</ul>
19+
</div>
20+
<section id="tab-syntax" class="tab-content is-active">
21+
<ul class="mt-0">
22+
<li>
23+
<strong>Single Term:</strong> Enter a single word to search for exact matches.<br>
24+
Example: <code>file.txt</code>
25+
</li>
26+
<li>
27+
<strong>Quoted Phrases:</strong> Use double quotes to search for exact phrases.<br>
28+
Example: <code>"name version"</code>
29+
</li>
30+
<li>
31+
<strong>Field Searches:</strong> Specify fields to narrow down your search.<br>
32+
Use <code>field_name:</code> followed by your search term.<br>
33+
Example: <code>name:file.txt</code></li>
34+
<li>
35+
<strong>Negation:</strong> Use a hyphen (-) before a field name to exclude results.<br>
36+
Example: <code>-name:file.txt</code></li>
37+
<li>
38+
<strong>Lookup Types:</strong> Use lookup types to perform specific searches.
39+
<ul>
40+
<li><code>=</code>: Exact match</li>
41+
<li><code>^</code>: Starts with</li>
42+
<li><code>$</code>: Ends with</li>
43+
<li><code>~</code>: Contains</li>
44+
<li><code>&gt;</code>: Greater than</li>
45+
<li><code>&lt;</code>: Less than</li>
46+
</ul>
47+
Example: <code>path^:dir1</code>
48+
</li>
49+
<li>
50+
<strong>Multiple queries</strong> are combined with the <code>AND</code> operator.<br>
51+
Example: <code>name:file.txt status:scanned</code>
52+
</li>
53+
</ul>
54+
</section>
55+
<section id="tab-fields" class="tab-content">
56+
<ul style="columns: 2;-webkit-columns: 2;-moz-columns: 2;">
57+
{% for field_name in searchable_fields %}
58+
<li>
59+
<code>{{ field_name }}</code>
60+
</li>
61+
{% endfor %}
62+
</ul>
63+
</section>
4364
</div>
44-
</section>
65+
</div>
4566
<footer class="modal-card-foot is-flex is-justify-content-space-between">
4667
<button class="button">Close</button>
4768
</footer>

scanpipe/views.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,14 @@ def get_context_data(self, **kwargs):
497497
query_dict.pop(PAGE_VAR, None)
498498
context["url_params_without_page"] = query_dict.urlencode()
499499

500+
context["searchable_fields"] = sorted(
501+
[
502+
field.name
503+
for field in self.model._meta.get_fields()
504+
if not field.is_relation
505+
]
506+
)
507+
500508
return context
501509

502510

0 commit comments

Comments
 (0)