Add ability to use field queries instead of term filters in ORQuery
authorJonathan Griffin <jgriffin@mozilla.com>
Tue, 07 Jun 2011 16:42:17 -0700
changeset 31 1f649c3998d0721b7152095416f534ff6a75f69f
parent 30 931345d8607ecd15ea57258374b47783cee7aa21
child 32 2edc7518de5abe9251e3b797db1405e6a63d7daf
push id32
push userjgriffin@mozilla.com
push dateTue, 07 Jun 2011 23:42:38 +0000
Add ability to use field queries instead of term filters in ORQuery
mozautoeslib/eslib.py
--- a/mozautoeslib/eslib.py
+++ b/mozautoeslib/eslib.py
@@ -69,17 +69,17 @@ class ESLib(object):
     boolquery = BoolQuery()
     self._add_fieldlist_to_boolquery(boolquery, include, True)
     self._add_fieldlist_to_boolquery(boolquery, exclude, False)
     if sort:
       boolquery.sort = sort
 
     return boolquery
 
-  def ORQuery(self, ORItems, size=10000, doc_type=None):
+  def ORQuery(self, ORItems, size=10000, doc_type=None, useFieldQueries=False):
     """Return a list of hits that match any of the combination of terms
        specified in the ORItems list of dicts.
 
        Example:
          return hits that match any of the following mahine/starttime
          combinations:
 
        result = eslib.ORQuery([
@@ -92,17 +92,20 @@ class ESLib(object):
       self.doc_type = doc_type
 
     resultlist = []
 
     orList = []
     for item in ORItems:
       andList = []
       for key in item:
-        andList.append(TermFilter(key, item[key]))
+        if useFieldQueries:
+          andList.append(QueryFilter(FieldQuery(FieldParameter(key, item[key]))))
+        else:
+          andList.append(TermFilter(key, item[key]))
       orList.append(ANDFilter(andList))
     orq = ORFilter(orList)
 
     q = FilteredQuery(MatchAllQuery(), orq)
     result = self.connection.search(query=q,
                                     size=size,
                                     indexes=[self.index],
                                     doc_types=self.doc_type)