I'm just getting started with Python, and I'm stuck on the syntax that I need to convert a set of request.POST parameters to Solr's query syntax.
The use case is a form defined like this:
class SearchForm(forms.Form):
text = forms.CharField()
metadata = forms.CharField()
figures = forms.CharField()
Upon submission, the form needs to generate a url-encoded string to pass to a URL client that looks like this:
text:myKeyword1+AND+metadata:myKeyword2+AND+figures:myKeyword3
Seems like there should be a simple way to do this. The closest I can get is
for f, v in request.POST.iteritems():
if v:
qstring += u'%s\u003A%s+and+' % (f,v)
However in that case the colon (\u003A) generates a Solr error because it is not getting encoded properly.
What is the clean way to do this?
Thanks!