<pre>
{ field: <pattern>, include: <include>, match: <query>, projection: <projection>, sort: <sort> }
</pre>
513754
public static Projection array(String pattern,
                                   Query match,
                                   boolean include,
                                   Projection projection,
                                   Sort sort) {
        Projection p = new Projection(false);
        p.add("field", pattern).add("include", include).add("match", match.toJson());
        if (projection != null) {
            p.add("projection", projection.toJson());
        }
        if (sort != null) {
            p.add("sort", sort.toJson());
        }
        return p;
    }
594417
function renderSearchFilters(req, fieldNames, data, modelName, cb) {

    if (!req) {
        throw new Error('req is required.');
    }

    if (!Array.isArray(fieldNames) || !fieldNames.length) {
        throw new Error('fieldNames is required and must be of type Array and cannot be empty.');
    }

    if (typeof modelName !== 'string' || !modelName.length) {
        throw new Error('modelName is required and must be of type String and cannot be empty.');
    }

    if (!(!Object.is(data, null) && !Array.isArray(data) && data === Object(data))) {
        throw new Error('data is required and must be of type Object.');
    }

    // Sort fieldNames (to make MongoDB queries more predictable, and therefore easier to create indexes for), remove duplicates, and remove anything that doesn't have associated data.
    fieldNames = dedupe(fieldNames.sort().filter(fieldName => Object.keys(data).indexOf(fieldName) >= 0));

    linz.api.model.list(req, modelName, function (err, list) {

        if (err) {
            return cb(err);
        }

        if (!Object.keys(list.filters).length) {
            return cb(null);
        }

        var model = linz.api.model.get(modelName),
            dataKeys = Object.keys(data),
            filters = {};

        async.each(fieldNames, function (fieldName, filtersDone) {

            if (!dataKeys.includes(fieldName)) {
                return filtersDone(null);
            }

            // call the filter renderer and update the content with the result
            list.filters[fieldName].filter.filter(fieldName, data, function (filterErr, result) {

                if (filterErr) {
                    return filtersDone(filterErr);
                }

                filters = model.addSearchFilter(filters, result);

                return filtersDone(null);

            });

        }, function (filterErr) {

            if (filterErr) {
                return cb(filterErr);
            }

            // consolidate filters into query
            filters = model.setFiltersAsQuery(filters);

            return cb(filterErr, filters);
        });

    });

}
1082237
function (items, query, fields, exact) {
        var self = this;
        var isTarget = function (fieldName) {
          return fields.indexOf(fieldName) !== -1;
        };
        if (query === '') {
          return items;
        }
        fields = fields || ['name', 'owner', 'description', 'keyword'];
        return _.filter(items, function (item) {
          if ((isTarget('name') && self.matchedInString(query, item.name, exact)) ||
              (isTarget('owner') && self.matchedInString(query, item.owner, exact)) ||
              (isTarget('description') && self.matchedInString(query, item.description, exact)) ||
              (isTarget('keyword') && self.matchedInArray(query, item.keywords, exact))) {
            return true;
          }
          return false;
        });
      }
746456
function getIncludes(file) {
    var content = String(file.contents);
    var matches = [];

    while (regexMatch = DIRECTIVE_REGEX.exec(content)) {
      matches.push(regexMatch);
    }

    // For every require fetch it's matching files
    var fileLists = _.map(matches, function(match) {
      return globMatch(match, file).sort();
    });

    // Merge all matching file lists into one concat list
    var order = _.reduce(fileLists, function(memo, fileList) {
      return _.union(memo, fileList);
    }, []);

    // And self to include list
    order.push(file.relative);
    return order;
  }
101403
public static Annotation[] findAnnotations(AbstractVariableDeclaration field, Pattern namePattern) {
		List<Annotation> result = new ArrayList<Annotation>();
		if (field.annotations == null) return EMPTY_ANNOTATIONS_ARRAY;
		for (Annotation annotation : field.annotations) {
			TypeReference typeRef = annotation.type;
			if (typeRef != null && typeRef.getTypeName() != null) {
				char[][] typeName = typeRef.getTypeName();
				String suspect = new String(typeName[typeName.length - 1]);
				if (namePattern.matcher(suspect).matches()) {
					result.add(annotation);
				}
			}
		}	
		return result.toArray(EMPTY_ANNOTATIONS_ARRAY);
	}
416700
private static int extractNonMatchingFields(Tuple<Type.Field> lhsFields, Tuple<Type.Field> rhsFields,
			Type.Field[] result, int index) {
		outer: for (int i = 0; i != lhsFields.size(); ++i) {
			for (int j = 0; j != rhsFields.size(); ++j) {
				Type.Field lhsField = lhsFields.get(i);
				Type.Field rhsField = rhsFields.get(j);
				Identifier lhsFieldName = lhsField.getName();
				Identifier rhsFieldName = rhsField.getName();
				if (lhsFieldName.equals(rhsFieldName)) {
					// This is a matching field. Therefore, continue on to the
					// next lhs field
					continue outer;
				}
			}
			result[index++] = lhsFields.get(i);
		}
		return index;
	}
971207
@Override
    protected boolean isMatching(final Field field) {

        if (!super.isMatching(field)) {
            return false;
        }

        final Resource resourceAnnotation = field.getAnnotation(Resource.class);
        if (resourceAnnotation == null) {
            return false;
        }

        return matchesResourceAnnotation(resourceAnnotation);
    }
1231165
@Override
    public org.apache.lucene.search.SortField sortField(Schema schema) {
        if (field.equalsIgnoreCase("score")) {
            return FIELD_SCORE;
        }
        Mapper mapper = schema.mapper(field);
        if (mapper == null) {
            throw new IndexException("No mapper found for sortFields field '{}'", field);
        } else if (!mapper.docValues) {
            throw new IndexException("Field '{}' does not support sorting", field);
        } else {
            return mapper.sortField(field, reverse);
        }
    }
179326
static List[] findTypos(Collection<String> fields, Mapping mapping) {
        Set<String> keys = mapping.flatten().keySet();

        // find missing
        List<String> missing = new ArrayList<String>(fields.size());

        for (String field : fields) {
            if (!keys.contains(field) && !isBuiltIn(field)) {
                missing.add(field);
            }
        }
        if (missing.isEmpty()) {
            return null;
        }
        Map<String, String> unwrapped = new LinkedHashMap<String, String>();
        // find similar
        for (String key : keys) {
            int match = key.lastIndexOf(".");
            if (match > 0) {
                String leafField = key.substring(match + 1);
                // leaf fields are secondary to top-level ones (in case of overwrite, the top level ones win)
                if (!unwrapped.containsKey(leafField)) {
                    unwrapped.put(leafField, key);
                }
            }
            unwrapped.put(key, key);
        }

        List<String> typos = new ArrayList<String>();

        Set<String> similar = unwrapped.keySet();
        for (String string : missing) {
            List<String> matches = StringUtils.findSimiliar(string, similar);
            for (String match : matches) {
                // get actual field
                typos.add(unwrapped.get(match));
            }
        }

        return new List[] { missing, typos };
    }
510719
public static Query withMatchingString(String field, String value, boolean caseInsensitive) {
        return caseInsensitive ? regex(field, escapeRegExPattern(value), caseInsensitive, false, false, false) : withValue(field, eq, value);
    }
485879
def to_match(self):
        """"""
        self.validate()

        mark_name, field_name = self.fold_scope_location.get_location_name()
        validate_safe_string(mark_name)

        template = u'$%(mark_name)s.%(field_name)s'
        template_data = {
            'mark_name': mark_name,
        }

        if field_name == COUNT_META_FIELD_NAME:
            template_data['field_name'] = 'size()'
        else:
            inner_type = strip_non_null_from_type(self.field_type.of_type)
            if GraphQLDate.is_same_type(inner_type):
                # Known OrientDB bug may cause trouble here, and incorrect data may be returned:
                # https://github.com/orientechnologies/orientdb/issues/7289
                template += '.format("' + STANDARD_DATE_FORMAT + '")'
            elif GraphQLDateTime.is_same_type(inner_type):
                # Known OrientDB bug may cause trouble here, and incorrect data may be returned:
                # https://github.com/orientechnologies/orientdb/issues/7289
                template += '.format("' + STANDARD_DATETIME_FORMAT + '")'

            template_data['field_name'] = field_name

        return template % template_data
458531
function(cb) {
      // For a basic match
      usableQueryKeys = [];
      Object.keys(query).forEach(function(k) {
        if (
          typeof query[k] === 'string' ||
          typeof query[k] === 'number' ||
          typeof query[k] === 'boolean' ||
          util.isDate(query[k]) ||
          query[k] === null
        ) {
          usableQueryKeys.push(k);
        }
      });
      usableQueryKeys = _.intersection(usableQueryKeys, indexNames);
      if (usableQueryKeys.length > 0) {
        return cb(null, self.indexes[usableQueryKeys[0]].getMatching(query[usableQueryKeys[0]]));
      }

      // For a $in match
      usableQueryKeys = [];
      Object.keys(query).forEach(function(k) {
        if (query[k] && query[k].hasOwnProperty('$in')) {
          usableQueryKeys.push(k);
        }
      });
      usableQueryKeys = _.intersection(usableQueryKeys, indexNames);
      if (usableQueryKeys.length > 0) {
        return cb(
          null,
          self.indexes[usableQueryKeys[0]].getMatching(query[usableQueryKeys[0]].$in),
        );
      }

      // For a comparison match
      usableQueryKeys = [];
      Object.keys(query).forEach(function(k) {
        if (
          query[k] &&
          (query[k].hasOwnProperty('$lt') ||
            query[k].hasOwnProperty('$lte') ||
            query[k].hasOwnProperty('$gt') ||
            query[k].hasOwnProperty('$gte'))
        ) {
          usableQueryKeys.push(k);
        }
      });
      usableQueryKeys = _.intersection(usableQueryKeys, indexNames);
      if (usableQueryKeys.length > 0) {
        return cb(
          null,
          self.indexes[usableQueryKeys[0]].getBetweenBounds(query[usableQueryKeys[0]]),
        );
      }

      // By default, return all the DB data
      return cb(null, self.getAllData());
    }
1023930
def lower_context_field_expressions(compound_match_query):
    """"""
    if len(compound_match_query.match_queries) == 0:
        raise AssertionError(u'Received CompoundMatchQuery {} with no MatchQuery objects.'
                             .format(compound_match_query))
    elif len(compound_match_query.match_queries) == 1:
        # All ContextFields exist if there is only one MatchQuery
        # becuase none of the traverses were omitted, and all locations exist (are defined).
        return compound_match_query
    else:
        new_match_queries = []
        for match_query in compound_match_query.match_queries:
            match_traversals = match_query.match_traversals
            present_locations, _ = _get_present_locations(match_traversals)
            current_visitor_fn = partial(_update_context_field_expression, present_locations)

            new_match_traversals = _lower_non_existent_context_field_filters(
                match_traversals, current_visitor_fn)
            new_match_queries.append(
                MatchQuery(
                    match_traversals=new_match_traversals,
                    folds=match_query.folds,
                    output_block=match_query.output_block,
                    where_block=match_query.where_block,
                )
            )

    return CompoundMatchQuery(match_queries=new_match_queries)
63407
function (query, items) {
            var sortExpressions = query.query.sort,
                self = this;

            if(sortExpressions){
                return items.sort(function (a, b) {
                    var sortExpression,
                        ret = 0;
                    for (var i = 0; i < sortExpressions.length; i++) {
                        sortExpression = sortExpressions[i];
                        ret = self._compareExpression(a, b, sortExpression);
                        if (ret !== 0) {
                            return ret;
                        }
                    }
                    return ret;
                });
            } else {
                return items;
            }

        }
988742
public List<ENTITY> find(List<Match> matches, List<Order> order) {
        return find(matches, order, 0, 0);
    }
883636
def to_match(self):
        """"""
        self.validate()

        mark_name, field_name = self.location.get_location_name()
        validate_safe_string(mark_name)
        validate_safe_string(field_name)

        stripped_field_type = strip_non_null_from_type(self.field_type)
        if GraphQLDate.is_same_type(stripped_field_type):
            return u'%s.%s.format("%s")' % (mark_name, field_name, STANDARD_DATE_FORMAT)
        elif GraphQLDateTime.is_same_type(stripped_field_type):
            return u'%s.%s.format("%s")' % (mark_name, field_name, STANDARD_DATETIME_FORMAT)
        else:
            return u'%s.%s' % (mark_name, field_name)
1325644
function (pattern, options) {
    var self = this;
    function find() {
      var isMatch = lazy.mm.matcher(pattern, options);
      for (var key in self) {
        var val = self[key];
        if (typeof val === 'object' && isMatch(key)) {
          return val;
        }
      }
    }
    var res = this.fragmentCache(pattern, find);
    res.__proto__ = this;
    return res;
  }