Skip to content

Commit c96b2b1

Browse files
akstrfnjelly
authored andcommitted
Widen the search results
Previously the search that had a space in it yields no results if the match is not exact e.g. ``archlinux keyring`` yields no results even though there is a package ``archlinux-keyring``. This patch modifies the query to search for ``archlinux AND keyring``, both for package names and package descriptions. This leads to more search results.
1 parent 2a8f534 commit c96b2b1

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

packages/views/search.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import operator
23

34
from django import forms
45
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
@@ -98,8 +99,11 @@ def parse_form(form, packages):
9899

99100
if form.cleaned_data['q']:
100101
query = form.cleaned_data['q']
101-
q = Q(pkgname__icontains=query) | Q(pkgdesc__icontains=query)
102-
packages = packages.filter(q)
102+
q_pkgname = reduce(operator.__and__,
103+
(Q(pkgname__icontains=q) for q in query.split()))
104+
q_pkgdesc = reduce(operator.__and__,
105+
(Q(pkgdesc__icontains=q) for q in query.split()))
106+
packages = packages.filter(q_pkgname | q_pkgdesc)
103107

104108
return packages
105109

0 commit comments

Comments
 (0)