Return a MATCH query string from a CompoundMatchQuery.
482326
def emit_code_from_ir(compound_match_query, compiler_metadata):
    """"""
    # If the compound match query contains only one match query,
    # just call `emit_code_from_single_match_query`
    # If there are multiple match queries, construct the query string for each
    # individual query and combine them as follows.
    #
    # SELECT EXPAND($result)
    # LET
    #    $optional__0 = (
    #        <query_string_0>
    #    ),
    #    $optional__1 = (
    #        <query_string_1>
    #    ),
    #    $optional__2 = (
    #        <query_string_2>
    #    ),
    #
    #    . . .
    #
    #    $result = UNIONALL($optional__0, $optional__1, . . . )

    match_queries = compound_match_query.match_queries
    if len(match_queries) == 1:
        query_string = emit_code_from_single_match_query(match_queries[0])
    elif len(match_queries) > 1:
        query_string = emit_code_from_multiple_match_queries(match_queries)
    else:
        raise AssertionError(u'Received CompoundMatchQuery with an empty list of MatchQueries: '
                             u'{}'.format(match_queries))

    return query_string
586199
def get_query(query_name):
    
    query_file_match = list(
        filter(lambda i: query_name == i.stem, FLAT_QUERIES))
    if not query_file_match:
        return None
    # TODO: Log warning if more than one match
    query_file = query_file_match[0]
    with open(query_file) as f:
        metadata, query_body = frontmatter.parse(f.read())
    result_mod = query_file.suffix.strip('.')
    query_obj = SimpleNamespace(
        name=query_name,
        metadata=metadata,
        path=query_file,
        result_mod=result_mod,
        body=query_body,
        error=False,
        executed=datetime.utcnow().isoformat())
    return query_obj
1021587
def search(self, query: Optional[dict] = None, offset: Optional[int] = None,
               limit: Optional[int] = None,
               order_by: Union[None, list, tuple] = None) -> Sequence['IModel']:
        """"""
        raise NotImplementedError
1008793
def normalize_query(query_string,
                    findterms=re.compile(r'"([^"]+)"|(\S+)').findall,
                    normspace=re.compile(r'\s{2,}').sub):
    

    return [normspace(' ', (t[0] or t[1]).strip()) for t in findterms(query_string)]
857599
def stringify_query(query):
        

        if isinstance(query, QueryBuilder):
            # Get string-representation of the passed :class:`pysnow.QueryBuilder` object
            return str(query)
        elif isinstance(query, dict):
            # Dict-type query
            return '^'.join(['%s=%s' % (k, v) for k, v in six.iteritems(query)])
        elif isinstance(query, six.string_types):
            # Regular string-type query
            return query
        else:
            raise InvalidUsage('Query must be of type string, dict or a QueryBuilder object')
1106604
def query_string_parser(search_pattern):
    """"""
    if not hasattr(current_oaiserver, 'query_parser'):
        query_parser = current_app.config['OAISERVER_QUERY_PARSER']
        if isinstance(query_parser, six.string_types):
            query_parser = import_string(query_parser)
        current_oaiserver.query_parser = query_parser
    return current_oaiserver.query_parser('query_string', query=search_pattern)
789923
def query( self ):
        
        # create the query compound
        if ( self.childCount() ):
            q = Q()
            operator = 'and'
            for i in range(self.childCount()):
                item = self.child(i)
                if ( isinstance(item, XQueryItem) ):
                    if ( operator == 'and' ):
                        q &= item.query()
                    else:
                        q |= item.query()
                else:
                    operator = nativestring(item.text(0))
            return q
        
        # create the query for this individual item
        else:
            q = Q(self.columnName())
            q.setOperatorType(self.operatorType())
            q.setValue(self.value())
            return q
319435
def regex_query(expression):
    """"""
    def _regex(index, expression=expression):
        """Return store key for documents that satisfy expression."""
        pattern = re.compile(expression)
        return [
            store_key
            for value, store_keys
            in index.get_index().items()
            if (isinstance(value, six.string_types)
                and re.match(pattern, value))
            for store_key in store_keys
        ]

    return _regex
507487
def query(self, search, query):
        
        if query:
            if self.fields:
                return search.query('multi_match', fields=self.fields, query=query)
            else:
                return search.query('multi_match', query=query)
        return search
1291068
def query(self):
        """"""
        if self._query is None:
            query_string = self.environ.get('QUERY_STRING')
            self._query = QueryDict([
                (k.decode('utf-8'), v.decode('utf-8'))
                for k, v in urlparse.parse_qsl(
                    query_string, keep_blank_values=True)
            ])
        return self._query
443984
def stringify_compound_key(self, key):
        """"""
        if UNQUOTED_COMPOUND_KEY.match(key):
            return key
        return self.escape_string(key)
823989
protected List<String> getMatchesWithClause(QueryData queryData, List<QueryNode> alternative,  String indent)
  {
    String indent2= indent + TABSTOP;
    String indent3 = indent2 + TABSTOP;
    
    StringBuilder sbRaw = new StringBuilder();
    sbRaw.append(indent).append("matchesRaw AS\n");
    sbRaw.append(indent).append("(\n");
    sbRaw.append(indent).append(getInnerQuerySqlGenerator().toSql(queryData, indent2));
    sbRaw.append("\n").append(indent).append(")");
    
    StringBuilder sbMatches = new StringBuilder();
    sbMatches.append(indent).append("matches AS\n");
    sbMatches.append(indent).append("(\n");
    
    int numOfNodes = queryData.getMaxWidth();
    for(int i=1; i <= numOfNodes; i++)
    {
      sbMatches.append(indent2)
        .append("SELECT\n");
      sbMatches.append(indent3).append("n").append(" AS n,\n");
      sbMatches.append(indent3).append(i).append(" AS nodeNr,\n");
      sbMatches.append(indent3).append("id").append(i).append(" AS id,\n");
      sbMatches.append(indent3).append("text").append(i).append(" AS \"text\",\n");
      sbMatches.append(indent3).append("min").append(i).append(" AS min,\n");
      sbMatches.append(indent3).append("max").append(i).append(" AS max,\n");
      sbMatches.append(indent3).append("corpus").append(i).append(" AS corpus\n");
      sbMatches.append(indent2).append("FROM matchesRaw\n");
      if(i < numOfNodes)
      {
        sbMatches.append(indent2).append("\n").append(indent2).append("UNION ALL\n\n");
      }
    }
    sbMatches.append("\n").append(indent).append(")");

    return Lists.newArrayList(sbRaw.toString(), sbMatches.toString());
  }
246035
def parse_querystring(self, req: Request, name: str, field: Field) -> typing.Any:
        """"""
        return core.get_value(req.query, name, field)
1173593
def query(options, collection_name, num_to_skip, num_to_return,
          query, field_selector, opts, check_keys=False, ctx=None):
    """"""
    if ctx:
        return _query_compressed(options, collection_name, num_to_skip,
                                 num_to_return, query, field_selector,
                                 opts, check_keys, ctx)
    return _query_uncompressed(options, collection_name, num_to_skip,
                               num_to_return, query, field_selector, opts,
                               check_keys)
354766
function(query) {
        var queryObj = {q: ''};
        if(!query) {
            return queryObj;
        }

        var qArray = query.split('&');
        var qObj = qs.parse(query);
        for(var i = 0, len = qArray.length; i < len; i++) {
            var queryItem = decodeURIComponent(qArray[i]).replace('=', '');
            if(/^\?/g.test(queryItem)) {
                debug('matched query: %s', queryItem) ;
                queryObj.q = queryItem;
                break;
            }
        }

        queryObj.m = qObj._mcss == 'true' || qObj._mcss == 'y';
        return queryObj;
    }
147712
def matches_query(self, key, query):
        
        dumped = query.dump()
        dumped['className'] = query._query_class._class_name
        self._add_condition(key, '$inQuery', dumped)
        return self
765311
def _query(options, collection_name, num_to_skip,
           num_to_return, query, field_selector, opts, check_keys):
    """"""
    encoded = _dict_to_bson(query, check_keys, opts)
    if field_selector:
        efs = _dict_to_bson(field_selector, False, opts)
    else:
        efs = b""
    max_bson_size = max(len(encoded), len(efs))
    return b"".join([
        _pack_int(options),
        _make_c_string(collection_name),
        _pack_int(num_to_skip),
        _pack_int(num_to_return),
        encoded,
        efs]), max_bson_size