Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Furkan Gursoy
Netzschleuder
Commits
98479a62
Commit
98479a62
authored
Sep 13, 2020
by
Tiago Peixoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for multiple regexp search
parent
619c2ec8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
10 deletions
+21
-10
net_site.py
net_site.py
+18
-7
templates/main.html
templates/main.html
+3
-3
No files found.
net_site.py
View file @
98479a62
...
...
@@ -92,21 +92,32 @@ def main_page():
if
tags
is
None
or
len
(
set
(
entry
.
tags
)
&
tags
)
>
0
]
else
:
fentries
=
entries
.
values
()
search
=
request
.
args
.
get
(
'search'
,
None
)
if
search
==
""
:
search
=
None
if
search
is
not
None
:
match
=
re
.
compile
(
search
)
def
score
(
vals
):
search
=
request
.
args
.
get
(
'search'
,
""
)
search
=
search
.
strip
()
if
search
!=
""
:
match
=
[]
for
s
in
re
.
split
(
r
'(?<!\\)&'
,
search
):
try
:
match
.
append
(
re
.
compile
(
s
.
strip
(),
re
.
IGNORECASE
))
except
re
.
error
:
pass
def
score_match
(
m
,
vals
):
n
=
0
for
v
in
vals
:
if
v
is
None
:
continue
if
isinstance
(
v
,
str
):
n
+=
len
(
m
atch
.
findall
(
v
))
n
+=
len
(
m
.
findall
(
v
))
else
:
n
+=
score
(
v
)
return
n
def
score
(
vals
):
n
=
1
for
m
in
match
:
n
*=
score_match
(
m
,
vals
)
if
n
==
0
:
break
return
n
fentries
=
[(
entry
,
score
([
entry
.
name
,
entry
.
title
,
entry
.
description
,
entry
.
url
,
entry
.
upstream_prefix
,
entry
.
citation
,
entry
.
upstream_license
,
...
...
templates/main.html
View file @
98479a62
...
...
@@ -14,8 +14,8 @@ active
<div
class=
"control-group all-100"
style=
"margin-bottom: 0"
>
<div
class=
"control append-button"
role=
"search"
>
<span>
{% if search
is none
%}
<input
type=
"text"
name=
"search"
id=
"search"
placeholder=
"
Enter arbitrary regexp term
"
>
{% if search
== ""
%}
<input
type=
"text"
name=
"search"
id=
"search"
placeholder=
"
Multiple regexp terms separated by '&'
"
>
{% else %}
<input
type=
"text"
name=
"search"
id=
"search"
,
value=
"{{search}}"
>
{% endif %}
...
...
@@ -32,7 +32,7 @@ active
{% endfor %}
<br/>
{% endif %}
{% if search
is not none
%}
{% if search
!= ""
%}
Showing only entries that match regexp: {{search}}
<br/>
{% endif %}
<span
style=
"font-size:x-small"
>
Tip: click on the table header to sort the list. Hover your mouse to obtain a legend.
</span>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment