Create a mongoose query based off of the request query
@param model: A mongoose model object.
@param query: The incoming request query.
@param mongooseQuery: A mongoose query.
@param logger: A logging object.
@returns {*}: A modified mongoose query.
558712
function(model, query, mongooseQuery, logger) {
    // This line has to come first
    validationHelper.validateModel(model, logger)
    const Log = logger.bind()
    // (email == 'test@user.com' && (firstName == 'test2@user.com' || firstName == 'test4@user.com')) && (age < 15 || age > 30)
    // LITERAL
    // {
    //  and: {
    //    email: {
    //      equal: 'test@user.com',
    //    },
    //    or: {
    //      firstName: {
    //        equal: ['test2@user.com', 'test4@user.com']
    //      }
    //    },
    //    age: {
    //      gt: '15',
    //      lt: '30'
    //    }
    //  }
    // {
    // and[email][equal]=test@user.com&and[or][firstName][equal]=test2@user.com&and[or][firstName][equal]=test4@user.com&and[age][gt]=15
    // ABBREVIATED
    // {
    //  email:'test@user.com',
    //  firstName: ['test2@user.com', 'test4@user.com'],
    //  age: {
    //    $or: {
    //      $gt: '15',
    //      $lt: '30'
    //    }
    //  }
    // }
    // [email]=test@user.com&[firstName]=test2@user.com&[firstName]=test4@user.com&[age][gt]=15&[age][lt]=30

    delete query[''] // EXPL: hack due to bug in hapi-swagger-docs

    delete query.$count

    mongooseQuery = this.setExclude(query, mongooseQuery, Log)

    let attributesFilter = this.createAttributesFilter(query, model, Log)
    if (attributesFilter === '') {
      attributesFilter = '_id'
    }

    let result = this.populateEmbeddedDocs(
      query,
      mongooseQuery,
      attributesFilter,
      model.routeOptions.associations,
      model,
      Log
    )
    mongooseQuery = result.mongooseQuery
    attributesFilter = result.attributesFilter

    mongooseQuery = this.setSort(query, mongooseQuery, Log)

    mongooseQuery.select(attributesFilter)

    if (typeof query.$where === 'string') {
      query.$where = JSON.parse(query.$where)
    }

    if (query.$where) {
      mongooseQuery.where(query.$where)
      delete query.$where
    }

    // EXPL: Support single (string) inputs or multiple "or'd" inputs (arrays) for field queries
    for (let fieldQueryKey in query) {
      let fieldQuery = query[fieldQueryKey]
      if (!Array.isArray(fieldQuery)) {
        fieldQuery = tryParseJSON(query[fieldQueryKey])
      }
      if (
        fieldQuery &&
        Array.isArray(fieldQuery) &&
        fieldQueryKey !== '$searchFields'
      ) {
        query[fieldQueryKey] = { $in: fieldQuery } // EXPL: "or" the inputs
      }
    }

    // EXPL: handle full text search
    if (query.$text) {
      query.$text = { $search: query.$text }
    }

    // EXPL: handle regex search
    this.setTermSearch(query, model, Log)

    let whereQuery = _.extend({}, query)

    // EXPL: delete pagination parameters
    delete whereQuery.$limit
    delete whereQuery.$skip
    delete whereQuery.$page

    mongooseQuery.where(whereQuery)
    return mongooseQuery
  }
620087
public static Long count(String query, Object... params) {
        return ModelDelegate.count(modelClass(), query, params);
    }
1132455
protected SolrQuery constructQuery(SolrDataQuery query, @Nullable Class<?> domainType) {
		return lookupQueryParser(query).constructSolrQuery(query, domainType);
	}
28020
function(query, model, logger) {
    // This line has to come first
    validationHelper.validateModel(model, logger)

    let attributesFilter = []
    let fields = model.schema.paths
    let fieldNames = []

    if (query.$select) {
      if (!Array.isArray(query.$select)) {
        query.$select = query.$select.split(',')
      }
      fieldNames = query.$select
    } else {
      fieldNames = Object.keys(fields)
    }

    let associations = model.routeOptions
      ? model.routeOptions.associations
      : null

    for (let i = 0; i < fieldNames.length; i++) {
      let fieldName = fieldNames[i]
      if (
        fields[fieldName] &&
        fieldName !== '__v' &&
        fieldName.substr(-2) !== '$*'
      ) {
        let field = fields[fieldName].options
        let association = associations
          ? associations[fields[fieldName].path] || {}
          : {}

        // EXPL: by default we don't include MANY_MANY array references
        if (
          !field.exclude &&
          (association.type !== 'MANY_MANY' || query.$select)
        ) {
          attributesFilter.push(fieldName)
        }
      }
    }

    delete query.$select
    return attributesFilter.toString().replace(/,/g, ' ')
  }
413387
public List executeQuery(QueryBuilder filter, AggregationBuilder aggregation, final EntityMetadata entityMetadata,
            KunderaQuery query, int firstResult, int maxResults)
    {
        String[] fieldsToSelect = query.getResult();
        Class clazz = entityMetadata.getEntityClazz();

        MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata()
                .getMetamodel(entityMetadata.getPersistenceUnit());

        FilteredQueryBuilder queryBuilder = QueryBuilders.filteredQuery(null, filter);
        SearchRequestBuilder builder = txClient.prepareSearch(entityMetadata.getSchema().toLowerCase())
                .setTypes(entityMetadata.getTableName());

        addFieldsToBuilder(fieldsToSelect, clazz, metaModel, builder);

        if (aggregation == null)
        {
            builder.setQuery(queryBuilder);
            builder.setFrom(firstResult);
            builder.setSize(maxResults);
            addSortOrder(builder, query, entityMetadata);
        }
        else
        {
            logger.debug("Aggregated query identified");
            builder.addAggregation(aggregation);

            if (fieldsToSelect.length == 1
                    || (query.isSelectStatement() && query.getSelectStatement().hasGroupByClause()))
            {
                builder.setSize(0);
            }
        }

        SearchResponse response = null;
        logger.debug("Query generated: " + builder);

        try
        {
            response = builder.execute().actionGet();
            logger.debug("Query execution response: " + response);
        }
        catch (ElasticsearchException e)
        {
            logger.error("Exception occured while executing query on Elasticsearch.", e);
            throw new KunderaException("Exception occured while executing query on Elasticsearch.", e);
        }

        return esResponseReader.parseResponse(response, aggregation, fieldsToSelect, metaModel, clazz, entityMetadata,
                query);
    }
255205
function createUriQueryMapper (query) {
  var parameters = extractQueryParameters(query);
  return (queryValues, args) => {
    queryValues = queryValues || Object.create(null);

    Object.keys(queryValues)
      .forEach(queryKey => {
        var parameter = parameters[queryKey];

        if (!parameter) {
          return;
        }

        var value = util.isArray(queryValues[queryKey]) ?
          queryValues[queryKey]
            .map(parameter.map)
            .filter(value => value !== null) :
          parameter.map(queryValues[queryKey]);

        if (value === null) {
          return;
        }

        args[parameter.name] = value;
      });
  };
}
929511
private <T> TypedQuery<T> onTypedQuery(Class<T> paramClass, Query q)
    {
        if (paramClass.equals(((QueryImpl) q).getKunderaQuery().getEntityClass()) || paramClass.equals(Object.class))
        {
            return new KunderaTypedQuery<T>(q);
        }

        throw new IllegalArgumentException("Mismatch in expected return type. Expected:" + paramClass
                + " But actual class is:" + ((QueryImpl) q).getKunderaQuery().getEntityClass());
    }
700823
private <T> Query<T> newQuery(final Class<T> type, final DBCollection collection, final DBObject query) {
        return getQueryFactory().createQuery(this, collection, type, query);
    }
217511
public static <R extends ActionRequestBuilder> R logRequestQuery(
            String method,
            R requestBuilder, Object... params) {
        if (params == null)
            JMLog.debug(log, method, requestBuilder);
        else
            JMLog.debug(log, method, Arrays.asList(params), requestBuilder);
        return requestBuilder;
    }
16288
function (query, indexName) {
        var model = this.collection.get(query, indexName);
        if (model && includes(this.models, model)) return model;
    }
380976
public Entity queryOne(String sql, Object... params) throws SQLException {
		return query(sql, new EntityHandler(), params);
	}
887497
public Query<S> query(Filter<S> filter, OrderingList<S> ordering, QueryHints hints)
        throws FetchException
    {
        filter = filter.bind();

        Map<OrderingList<S>, Query<S>> map;
        synchronized (mFilterToQuery) {
            map = mFilterToQuery.get(filter);
            if (map == null) {
                if (filter == null) {
                    throw new IllegalArgumentException("Query filter must not be null");
                }
                map = new SoftValuedHashMap(7);
                mFilterToQuery.put(filter, map);
            }
        }

        Query<S> query;
        synchronized (map) {
            query = map.get(ordering);
            if (query == null) {
                FilterValues<S> values = filter.initialFilterValues();
                if (values == null && filter.isClosed()) {
                    query = new EmptyQuery<S>(this, ordering);
                } else {
                    StandardQuery<S> standardQuery = createQuery(filter, values, ordering, hints);
                    if (!mLazySetExecutor) {
                        try {
                            standardQuery.setExecutor();
                        } catch (RepositoryException e) {
                            throw e.toFetchException();
                        }
                    }
                    query = standardQuery;
                }
                map.put(ordering, query);
            }
        }

        return query;
    }
773383
function(model, logger) {
    // This line has to come first
    validationHelper.validateModel(model, logger)

    let queryableFields = []

    let fields = model.schema.paths
    let fieldNames = Object.keys(fields)

    let associations = model.routeOptions
      ? model.routeOptions.associations
      : null

    for (let i = 0; i < fieldNames.length; i++) {
      let fieldName = fieldNames[i]
      if (fields[fieldName] && fieldName !== '__v' && fieldName !== '__t') {
        let field = fields[fieldName].options
        let association = associations
          ? associations[fields[fieldName].path] || {}
          : {}

        // EXPL: by default we don't include MANY_MANY array references
        if (
          field.queryable !== false &&
          !field.exclude &&
          association.type !== 'MANY_MANY'
        ) {
          queryableFields.push(fieldName)
        }
      }
    }

    return queryableFields
  }
1100471
function(model, settings, options, cb) {
      var baseQuery, defaultSelect, k, query, v;
      if (settings == null) {
        settings = {};
      }
      if (options == null) {
        options = {};
      }
      if (cb == null) {
        cb = function() {};
      }
      Hoek.assert(model, i18n.assertModuleRequired);
      defaultSelect = settings.defaultSelect || null;
      baseQuery = settings.baseQuery || {};
      if (_.isFunction(options)) {
        cb = options;
        options = {};
      }
      options.where || (options.where = {});
      options.select || (options.select = defaultSelect);
      for (k in baseQuery) {
        v = baseQuery[k];
        options.where[k] = v;
      }
      query = model.findOne(options.where);
      if (options.select && options.select.length > 0) {
        query = query.select(options.select);
      }
      return query.exec(cb);
    }
980607
def query_model(self, model, condition=None, offset=None, limit=None,
                    group_by=None, having=None, order_by=None, fields=None):
        
        if self._query is not None:
            query = self._query
        else:
            query = self.get_select()
            
        if condition is not None:
            if isinstance(query, Result):
                query = query.filter(condition)
            else:
                query = query.where(condition)
        if self.pagination:
            if offset is not None:
                query = query.offset(int(offset))
            if limit is not None:
                query = query.limit(int(limit))
        if order_by is not None:
            if isinstance(order_by, (tuple, list)):
                for order in order_by:
                    query = query.order_by(order)
            else:
                query = query.order_by(order_by)
        if group_by is not None:
            if isinstance(group_by, (tuple, list)):
                query = query.group_by(*group_by)
            else:
                query = query.group_by(group_by)
            if having is not None:
                query = query.having(having)
        return query
164978
def search(query, model):
    
    query = query.strip()
    LOGGER.debug(query)
    sqs = SearchQuerySet()
    results = sqs.raw_search('{}*'.format(query)).models(model)
    if not results:
        results = sqs.raw_search('*{}'.format(query)).models(model)
    if not results:
        results = sqs.raw_search('*{}*'.format(query)).models(model)

    return [o.pk for o in results]
98448
def _one_to_many_query(cls, query_obj, search4, model_attrib):
        
        model = model_attrib.parent.class_

        already_joined_tables = [mapper.class_ for mapper in query_obj._join_entities]

        if isinstance(search4, (str, int, Iterable)) and model not in already_joined_tables:
            query_obj = query_obj.join(model)

        if isinstance(search4, str):
            query_obj = query_obj.filter(model_attrib.like(search4))

        elif isinstance(search4, int):
            query_obj = query_obj.filter(model_attrib == search4)

        elif isinstance(search4, Iterable):
            query_obj = query_obj.filter(model_attrib.in_(search4))

        return query_obj