Пример #1
0
 def from_strings(cls, query_parts, default_fields=None, all_keys=ITEM_KEYS):
     """Creates a query from a list of strings in the format used by
     _parse_query_part. If default_fields are specified, they are the
     fields to be searched by unqualified search terms. Otherwise,
     all fields are searched for those terms.
     """
     subqueries = []
     for part in query_parts:
         res = cls._parse_query_part(part)
         if not res:
             continue
         key, pattern = res
         if key is None:  # No key specified.
             if os.sep in pattern and "path" in all_keys:
                 # This looks like a path.
                 subqueries.append(PathQuery(pattern))
             else:
                 # Match any field.
                 subqueries.append(AnySubstringQuery(pattern, default_fields))
         elif key.lower() == "comp":  # a boolean field
             subqueries.append(BooleanQuery(key.lower(), pattern))
         elif key.lower() == "path" and "path" in all_keys:
             subqueries.append(PathQuery(pattern))
         elif key.lower() in all_keys:  # ignore unrecognized keys
             subqueries.append(SubstringQuery(key.lower(), pattern))
         elif key.lower() == "singleton":
             subqueries.append(SingletonQuery(util.str2bool(pattern)))
     if not subqueries:  # no terms in query
         subqueries = [TrueQuery()]
     return cls(subqueries)
Пример #2
0
 def from_strings(cls,
                  query_parts,
                  default_fields=None,
                  all_keys=ITEM_KEYS):
     """Creates a query from a list of strings in the format used by
     _parse_query_part. If default_fields are specified, they are the
     fields to be searched by unqualified search terms. Otherwise,
     all fields are searched for those terms.
     """
     subqueries = []
     for part in query_parts:
         res = cls._parse_query_part(part)
         if not res:
             continue
         key, pattern = res
         if key is None:  # No key specified.
             if os.sep in pattern:
                 # This looks like a path.
                 subqueries.append(PathQuery(pattern))
             else:
                 # Match any field.
                 subqueries.append(
                     AnySubstringQuery(pattern, default_fields))
         elif key.lower() == 'comp':  # a boolean field
             subqueries.append(BooleanQuery(key.lower(), pattern))
         elif key.lower() == 'path':
             subqueries.append(PathQuery(pattern))
         elif key.lower() in all_keys:  # ignore unrecognized keys
             subqueries.append(SubstringQuery(key.lower(), pattern))
         elif key.lower() == 'singleton':
             subqueries.append(SingletonQuery(util.str2bool(pattern)))
     if not subqueries:  # no terms in query
         subqueries = [TrueQuery()]
     return cls(subqueries)
Пример #3
0
 def from_string(cls, query_string, default_fields=None, all_keys=ITEM_KEYS):
     """Creates a query from a string in the format used by
     _parse_query. If default_fields are specified, they are the
     fields to be searched by unqualified search terms. Otherwise,
     all fields are searched for those terms.
     """
     subqueries = []
     for key, pattern in cls._parse_query(query_string):
         if key is None: # no key specified; match any field
             subqueries.append(AnySubstringQuery(pattern, default_fields))
         elif key.lower() == 'comp': # a boolean field
             subqueries.append(BooleanQuery(key.lower(), pattern))
         elif key.lower() in all_keys: # ignore unrecognized keys
             subqueries.append(SubstringQuery(key.lower(), pattern))
         elif key.lower() == 'singleton':
             subqueries.append(SingletonQuery(util.str2bool(pattern)))
         elif key.lower() == 'path':
             subqueries.append(PathQuery(pattern))
     if not subqueries: # no terms in query
         subqueries = [TrueQuery()]
     return cls(subqueries)
Пример #4
0
 def __init__(self, field, pattern):
     super(BooleanQuery, self).__init__(field, pattern)
     if isinstance(pattern, basestring):
         self.pattern = util.str2bool(pattern)
     self.pattern = int(self.pattern)
Пример #5
0
 def __init__(self, field, pattern):
     super(BooleanQuery, self).__init__(field, pattern)
     if isinstance(pattern, basestring):
         self.pattern = util.str2bool(pattern)
     self.pattern = int(self.pattern)