Any idea to set q.op in pysolr?

358 views Asked by At

The following code doesn't work.... any idea? thanks. Couldn't find any reference about it...

import pysolr
....

self.solr = pysolr.Solr(solr_url, timeout=20)
docs = self.solr.search(q=q, q.op =q_op)

Can I just use self.solr.search(q=q, op =q_op) instead ?

1

There are 1 answers

0
MatsLindh On BEST ANSWER

You can't use names with . directly in parameters in python, since they indicate an object reference (i.e. datetime.datetime, solr.search() etc.).

You can work around this by giving the properties as a dictionary which expands to parameters to the search function:

results = solr.search(q=q, **{
            'q.op': 'AND'
          })

The relevant code from pysolr:

"""
# Search with highlighting.
results = solr.search('ponies', **{
        'hl': 'true',
        'hl.fragsize': 10,
    })
"""

params = {'q': q}
params.update(kwargs)