summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2014-10-18 18:28:26 -0500
committerDan McGee <dan@archlinux.org>2014-10-18 18:28:26 -0500
commit061805aa73d3d5b418a61fa6d6591d1a7d03d9ed (patch)
treeb7cd8cca5eba3c358a000b399cc2cd756b88b6a1
parent4def86ec76d9975be8a357b6fc06104cc2b31fed (diff)
downloadarchweb-061805aa73d3d5b418a61fa6d6591d1a7d03d9ed.tar.gz
archweb-061805aa73d3d5b418a61fa6d6591d1a7d03d9ed.zip
FS#30773: put exact matches at top
There have been a few proposed solutions to this, but there really isn't anything without a drawback. Things break pagination, require loading the entire result set from the database, etc. Just plop a new table on the page if someone did a so-called "simple" search and we have a match. Only show on the first page of the search results. This results in a relatively fast experience for someone doing something like searching for the "perl" package. Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--packages/views/search.py6
-rw-r--r--templates/packages/search.html36
-rw-r--r--templates/packages/search_paginator.html4
3 files changed, 44 insertions, 2 deletions
diff --git a/packages/views/search.py b/packages/views/search.py
index b3778172..0b776d79 100644
--- a/packages/views/search.py
+++ b/packages/views/search.py
@@ -45,6 +45,12 @@ class PackageSearchForm(forms.Form):
[('', 'All'), ('unknown', 'Unknown')] + \
[(m.username, m.get_full_name()) for m in maints]
+ def exact_matches(self):
+ # only do exact match search if 'q' is sole parameter
+ if self.changed_data != ['q']:
+ return []
+ return Package.objects.normal().filter(pkgname=self.cleaned_data['q'])
+
def parse_form(form, packages):
if form.cleaned_data['repo']:
diff --git a/templates/packages/search.html b/templates/packages/search.html
index db86fb67..ca95c3f0 100644
--- a/templates/packages/search.html
+++ b/templates/packages/search.html
@@ -40,6 +40,42 @@
</form>
</div>
+{% if not is_paginated or page_obj.number == 1 %}{% with search_form.exact_matches as exact_matches %}{% if exact_matches %}
+<div id="exact-matches" class="box">
+ <div class="pkglist-stats">
+ <p>{{ exact_matches|length }} exact match{{ exact_matches|pluralize:"es" }} found.</p>
+ </div>
+ <table class="results">
+ <thead>
+ <tr>
+ <th>Arch</th>
+ <th>Repo</th>
+ <th>Name</th>
+ <th>Version</th>
+ <th>Description</th>
+ <th>Last Updated</th>
+ <th>Flag Date</th>
+ </tr>
+ </thead>
+ <tbody>
+ {% for pkg in exact_matches %}<tr class="{% cycle 'odd' 'even' %}">
+ <td>{{ pkg.arch.name }}</td>
+ <td>{{ pkg.repo.name|capfirst }}</td>
+ <td>{% pkg_details_link pkg %}</td>
+ {% if pkg.flag_date %}
+ <td><span class="flagged">{{ pkg.full_version }}</span></td>
+ {% else %}
+ <td>{{ pkg.full_version }}</td>
+ {% endif %}
+ <td class="wrap">{{ pkg.pkgdesc }}</td>
+ <td>{{ pkg.last_update|date }}</td>
+ <td>{{ pkg.flag_date|date }}</td>
+ </tr>{% endfor %}
+ </tbody>
+ </table>
+</div>
+{% endif %}{% endwith %}{% endif %}
+
{% if package_list %}
<div id="pkglist-results" class="box">
{% include "packages/search_paginator.html" %}
diff --git a/templates/packages/search_paginator.html b/templates/packages/search_paginator.html
index 4c2bef03..a748d26b 100644
--- a/templates/packages/search_paginator.html
+++ b/templates/packages/search_paginator.html
@@ -1,6 +1,6 @@
<div class="pkglist-stats">
{% if is_paginated %}
- <p>{{ paginator.count }} packages found.
+ <p>{{ paginator.count }} matching packages found.
Page {{ page_obj.number }} of {{ paginator.num_pages }}.</p>
<div class="pkglist-nav">
@@ -22,6 +22,6 @@
</span>
</div>
{% else %}
- <p>{{ package_list|length }} packages found.</p>
+ <p>{{ package_list|length }} matching package{{ package_list|pluralize }} found.</p>
{% endif %}
</div>