Constructing a query from a list of terms

34 views
Skip to first unread message

Alex Willmer

unread,
Mar 27, 2012, 8:14:46 AM3/27/12
to Python Sunburnt
In the project I'm working on a document has a single realm, we filter
results by whether the document's realm matches any of a list of
realms (i.e. fq="realm:realm1 OR realm:realm2 OR realm:realm3 ...." ).

So far the best way I've found to construct this filter query is

import operator
Q = solr_iface.query().Q
if realms:
fq = reduce(operator.or_, [Q(u'realm:%s' % realm) for realm in
realms])
else:
fq = solr_iface.query()

Is there a better way?

Many thanks, Alex
Reply all
Reply to author
Forward
0 new messages