From 061805aa73d3d5b418a61fa6d6591d1a7d03d9ed Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sat, 18 Oct 2014 18:28:26 -0500 Subject: 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 --- packages/views/search.py | 6 ++++++ templates/packages/search.html | 36 ++++++++++++++++++++++++++++++++ templates/packages/search_paginator.html | 4 ++-- 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 @@ def __init__(self, *args, **kwargs): [('', '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 @@

Package Search

+{% if not is_paginated or page_obj.number == 1 %}{% with search_form.exact_matches as exact_matches %}{% if exact_matches %} +
+
+

{{ exact_matches|length }} exact match{{ exact_matches|pluralize:"es" }} found.

+
+ + + + + + + + + + + + + + {% for pkg in exact_matches %} + + + + {% if pkg.flag_date %} + + {% else %} + + {% endif %} + + + + {% endfor %} + +
ArchRepoNameVersionDescriptionLast UpdatedFlag Date
{{ pkg.arch.name }}{{ pkg.repo.name|capfirst }}{% pkg_details_link pkg %}{{ pkg.full_version }}{{ pkg.full_version }}{{ pkg.pkgdesc }}{{ pkg.last_update|date }}{{ pkg.flag_date|date }}
+
+{% endif %}{% endwith %}{% endif %} + {% if package_list %}
{% 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 @@
{% if is_paginated %} -

{{ paginator.count }} packages found. +

{{ paginator.count }} matching packages found. Page {{ page_obj.number }} of {{ paginator.num_pages }}.

@@ -22,6 +22,6 @@
{% else %} -

{{ package_list|length }} packages found.

+

{{ package_list|length }} matching package{{ package_list|pluralize }} found.

{% endif %}
-- cgit v1.2.3-54-g00ecf