summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--packages/views/search.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/packages/views/search.py b/packages/views/search.py
index b377817..a01de4d 100644
--- a/packages/views/search.py
+++ b/packages/views/search.py
@@ -116,6 +116,18 @@ class SearchListView(ListView):
packages = packages.order_by(sort)
else:
packages = packages.order_by('pkgname')
+
+ if self.form.cleaned_data['q']:
+ # put exact matches first
+ qs1 = packages.filter(pkgname__iexact=self.form.cleaned_data['q'])
+ qs2 = packages.exclude(pkgname__iexact=self.form.cleaned_data['q'])
+
+ # https://stackoverflow.com/questions/18235419/how-to-chain-django-querysets-preserving-individual-order
+ len(qs1)
+ for q in qs2:
+ qs1._result_cache.append(q)
+ packages = qs1
+
return packages
# Form had errors so don't return any results