Search like github: is:open is:pr author:me ...

I like the search syntax from github:

is:open is:pr author:me …

image

Before I re-invent the wheel: Is there something like this for Django?

I tried to find something with my favorite search engine, but failed.

Hi @guettli.

For the filtering you can use django-filter.

Then a FilterSet expects (normally) a QueryDict, which you need because you have repeated is keys.

So to create that you need to parse the query string. Something like:

>>> from django.http import QueryDict
>>> query = "is:open is:pr author:me"
>>> parts = [item.split(":") for item in query.split(" ")]
>>> parts
[['is', 'open'], ['is', 'pr'], ['author', 'me']]
>>> qd = QueryDict("", mutable=True)
>>> for p in parts:
...    qd.appendlist(p[0], p[1])
...
>>> qd
<QueryDict: {'is': ['open', 'pr'], 'author': ['me']}>

No doubt you’ll need to add a bit of bulletproofing. :slight_smile:

Hope that helps.

1 Like