Skip to content
Permalink
Browse files

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.
  • Loading branch information...
akstrfn authored and jelly committed Jun 24, 2018
1 parent 2a8f534 commit c96b2b1b0aa722482705e2851d6dfe32288620de
Showing with 6 additions and 2 deletions.
  1. +6 −2 packages/views/search.py
@@ -1,4 +1,5 @@
import json
import operator

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

if form.cleaned_data['q']:
query = form.cleaned_data['q']
q = Q(pkgname__icontains=query) | Q(pkgdesc__icontains=query)
packages = packages.filter(q)
q_pkgname = reduce(operator.__and__,
(Q(pkgname__icontains=q) for q in query.split()))
q_pkgdesc = reduce(operator.__and__,
(Q(pkgdesc__icontains=q) for q in query.split()))
packages = packages.filter(q_pkgname | q_pkgdesc)

return packages

0 comments on commit c96b2b1

Please sign in to comment.
You can’t perform that action at this time.