diff options
author | Florian Pritz <bluewind@xinu.at> | 2014-09-05 15:09:51 +0200 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2014-09-05 15:09:51 +0200 |
commit | 86307ca2a7d643d8975d5c9cab551e30d0dcbb07 (patch) | |
tree | f656587b404e0d1f5a7b35be74d908fbec125448 | |
parent | a8ceba34299cca271ddf433bf7618aa98e56cc36 (diff) | |
download | archweb-working.tar.gz archweb-working.tar.xz |
FS#30773 - package search: put exact match at the topworking
This might not be the cleanest or best performing solution, but it
works.
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rw-r--r-- | packages/views/search.py | 12 |
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 |