diff options
author | Dan McGee <dan@archlinux.org> | 2012-08-20 21:19:02 -0500 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2012-08-20 21:19:02 -0500 |
commit | f7289625000d0f83675fc5a70650b49707338dca (patch) | |
tree | 4e895cbbc269ac6c03ccf00f9e8c4516eb1d3acf | |
parent | 0ec1af27aeb2ff94128c84ad53f09045cd9ee6e3 (diff) |
Use case-insensitive search in opensearch suggestions
There is no real good reason not to do this, since our packages are
lowercased by convention.
Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r-- | packages/views/__init__.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/packages/views/__init__.py b/packages/views/__init__.py index 038d40ac..f7952255 100644 --- a/packages/views/__init__.py +++ b/packages/views/__init__.py @@ -5,6 +5,7 @@ from django.contrib import messages from django.contrib.auth.decorators import permission_required from django.contrib.auth.models import User from django.core.cache import cache +from django.db.models import Q from django.http import HttpResponse from django.shortcuts import redirect, render from django.views.decorators.cache import cache_control @@ -47,8 +48,13 @@ def opensearch_suggest(request): hashlib.md5(search_term.encode('utf-8')).hexdigest() to_json = cache.get(cache_key, None) if to_json is None: - names = Package.objects.filter( - pkgname__startswith=search_term).values_list( + q = Q(pkgname__startswith=search_term) + lookup = search_term.lower() + if search_term != lookup: + # package names are lowercase by convention, so include that in + # search if original wasn't lowercase already + q |= Q(pkgname__startswith=lookup) + names = Package.objects.filter(q).values_list( 'pkgname', flat=True).order_by('pkgname').distinct()[:10] results = [search_term, list(names)] to_json = json.dumps(results, ensure_ascii=False) |