The Q operator and chaining querystring query

35 views
Skip to first unread message

Masud

unread,
Mar 18, 2013, 5:22:24 AM3/18/13
to python-...@googlegroups.com
Hi all,

I am currently finding it difficult to perform an AND operation by chaining the query from the query string. E.g. if my query string has the values "coffee mba" without the quotes, I am not able to do anything more than:

query = request.GET['q']
query_operation = request.GET['query_operation']

if query_operation == 'and':
    query_terms = query.split()
    for term in query_terms:
        q = solr.Q("%s") % term            ### Not sure about this line, I can't even do q &= .. 

Can someone kindly help in how to concatenate this query?

Thanks a lot for your help in advance.

Best wishes,
Masud



Masud

unread,
Mar 18, 2013, 5:37:29 AM3/18/13
to python-...@googlegroups.com
Found a solution so posting it here.

query = request.GET['q']
query_operation = request.GET['query_operation']

if query_operation == 'and':
    query_terms = query.split()
    q = solr.Q()
    for term in query_terms:
        query_args = {field: term}
        q = (solr.Q(**query_args)) & q
Reply all
Reply to author
Forward
0 new messages