Commit 98479a62 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Add support for multiple regexp search

parent 619c2ec8
......@@ -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(match.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,
......
......@@ -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>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment