/*
Example:

MATCH (n:ENTITY:table)
WHERE (n.id.property1 = {0} AND n.id.property2 = {1} ) OR (n.id.property1 = {2} AND n.id.property2 = {3} )
RETURN n
499341
private String createMultiGetOnMultiplePropertiesId(int keysNumber) {
		StringBuilder builder = new StringBuilder( multiGetQuery );
		int counter = 0;
		for ( int row = 0; row < keysNumber; row++ ) {
			builder.append( "(" );
			for ( int col = 0; col < keyColumns.length; col++ ) {
				builder.append( ENTITY_ALIAS );
				builder.append( "." );
				escapeIdentifier( builder, keyColumns[col] );
				builder.append( " = {" );
				builder.append( counter++ );
				builder.append( "}" );
				if ( col < keyColumns.length - 1 ) {
					builder.append( " AND " );
				}
			}
			builder.append( ")" );
			if ( row < keysNumber - 1 ) {
				builder.append( " OR " );
			}
		}
		appendGetEmbeddedNodesIfNeeded( includeEmbedded, builder );
		return builder.toString();
	}
1331662
def key_match?(type, keys, doc)

      _id = doc.is_a?(Hash) ? doc['_id'] : doc

      if keys.first.is_a?(String) && type == 'schedules'
        keys.find { |key| _id.match(/#{key}-\d+$/) }
      elsif keys.first.is_a?(String)
        keys.find { |key| _id.end_with?(key) }
      else # Regexp
        keys.find { |key| _id.match(key) }
      end
    end
1022509
public List<ENTITY> page(List<Match> matches, List<Order> order, int curPage, int pageSize) {

        if (curPage < 0 || pageSize < 0) {
            return find(matches, order);
        }

        int offset = (curPage) * pageSize;
        int limit = pageSize;
        return find(matches, order, offset, limit);
    }
178978
def _validate_filters_ndb(cls, filters, model_class):
    """"""
    if not filters:
      return

    properties = model_class._properties


    for idx, f in enumerate(filters):
      prop, ineq, val = f
      if prop not in properties:
        raise errors.BadReaderParamsError(
            "Property %s is not defined for entity type %s",
            prop, model_class._get_kind())

      # Attempt to cast the value to a KeyProperty if appropriate.
      # This enables filtering against keys.
      try:
        if (isinstance(val, basestring) and
            isinstance(properties[prop],
              (ndb.KeyProperty, ndb.ComputedProperty))):
          val = ndb.Key(urlsafe=val)
          filters[idx] = [prop, ineq, val]
      except:
        pass

      # Validate the value of each filter. We need to know filters have
      # valid value to carry out splits.
      try:
        properties[prop]._do_validate(val)
      except db.BadValueError, e:
        raise errors.BadReaderParamsError(e)
713081
function matchToHolders(match, tag) {
  return object(match.map(function(val, index) {
    return [tag+":"+index, val];
  }));
}
438536
function findOne(repository, options) {
    const entityPrimaryKeyColumn = lodash_1.find(repository.metadata.columns, (columnMetadata) => columnMetadata.isPrimary).propertyName;
    const entityColumns = repository.metadata.columns.map((columnMetadata) => columnMetadata.propertyName);
    const entityManyToOneOrOneToOneRelationColumns = repository
        .metadata
        .relations
        .filter((relationMetadata) => relationMetadata.relationType === 'many-to-one' || relationMetadata.relationType === 'one-to-one')
        .map((relationMetadata) => relationMetadata.propertyName);
    const entityUniqueColumns = repository
        .metadata
        .columns
        .filter((columnMetadata) => columnMetadata.isUnique)
        .map((columnMetadata) => columnMetadata.propertyName);
    return function (source, args, context, info) {
        return __awaiter(this, void 0, void 0, function* () {
            const selectedColumns = Object.keys(graphqlFields(info));
            const selectQueryBuilder = repository.createQueryBuilder(repository.metadata.name.toLowerCase());
            /** Select **/
            const selectFactory = new select_factory_1.SelectFactory(selectQueryBuilder);
            selectFactory
                .select(selectedColumns.filter((select) => entityColumns.includes(select)));
            /** Where **/
            const filter = Object
                .keys(args)
                .filter((argName) => entityUniqueColumns.includes(argName) || argName === entityPrimaryKeyColumn)
                .reduce((filteredArgs, argName) => {
                filteredArgs[argName] = args[argName];
                return filteredArgs;
            }, {});
            const whereFactory = new where_factory_1.WhereFactory(selectQueryBuilder, entityManyToOneOrOneToOneRelationColumns);
            whereFactory
                .where(filter);
            /** Joins **/
            const joinsFactory = new joins_factory_1.JoinsFactory(selectQueryBuilder);
            joinsFactory
                .join(selectedColumns
                .filter((select) => entityManyToOneOrOneToOneRelationColumns.includes(select))
                .reduce((selectedRelationColumns, selectedRelationColumn) => {
                selectedRelationColumns[selectQueryBuilder.alias] = selectedRelationColumn;
                return selectedRelationColumns;
            }, {}))
                .join(whereFactory.selectedManyToOneOrOneToOneRelationColumns);
            /** Extend **/
            if (lodash_1.get(options, 'extend')) {
                yield options.extend(selectQueryBuilder);
            }
            /** Execute get many method **/
            return yield selectQueryBuilder.getOne();
        });
    };
}
1062533
private static String initMatchOwnerEntityNode(EntityKeyMetadata ownerEntityKeyMetadata) {
		StringBuilder queryBuilder = new StringBuilder();
		appendMatchOwnerEntityNode( queryBuilder, ownerEntityKeyMetadata );
		return queryBuilder.toString();
	}
238113
function match (obj, query) {
  var queryKeys, queryKey, queryValue, i;

  // Primitive query against a primitive type
  // This is a bit of a hack since we construct an object with an arbitrary key only to dereference it later
  // But I don't have time for a cleaner implementation now
  if (isPrimitiveType(obj) || isPrimitiveType(query)) {
    return matchQueryPart({ needAKey: obj }, 'needAKey', query);
  }
    
  // Normal query
  queryKeys = Object.keys(query);
  for (i = 0; i < queryKeys.length; i += 1) {
    queryKey = queryKeys[i];
    queryValue = query[queryKey];
  
    if (queryKey[0] === '$') {
      if (!logicalOperators[queryKey]) { throw "Unknown logical operator " + queryKey; }
      if (!logicalOperators[queryKey](obj, queryValue)) { return false; }
    } else {
      if (!matchQueryPart(obj, queryKey, queryValue)) { return false; }
    }
  }

  return true;
}
243554
def query_property_filter(query, options)
      if options[:where]
        opts = options[:where]
        if opts[0].is_a?(Array)
          opts.each do |opt|
            query.where(opt[0], opt[1], opt[2]) unless opt.nil?
          end
        else
          query.where(opts[0], opts[1], opts[2])
        end
      end
      query
    end
383890
def _validate_filters_ndb(cls, filters, model_class):
    """"""
    if not filters:
      return

    properties = model_class._properties

    for f in filters:
      prop, _, val = f
      if prop not in properties:
        raise errors.BadReaderParamsError(
            "Property %s is not defined for entity type %s",
            prop, model_class._get_kind())

      # Validate the value of each filter. We need to know filters have
      # valid value to carry out splits.
      try:
        properties[prop]._do_validate(val)
      except db.BadValueError, e:
        raise errors.BadReaderParamsError(e)
86255
function matchRoute(route, path) {

  if (route.pattern === undefined && route.path !== undefined) {
    var routePattern;

    if (route.path instanceof RegExp) {
      routePattern = route.path;
    } else {
      var routePath = normalize(route.path);
      routePattern = route.children.length > 0 ? routePath + '*' : routePath;
    }

    Object.defineProperty(route, 'pattern', {
      enumerable: false,
      value: pattern.newPattern(routePattern)
    });
  }

  if (route.pattern) {
    var match = route.pattern.match(path);

    if (match) {
      if (route.pattern.isRegex) {
        match = {_: match};
      }

      if (!match._ || match._[0] === '/' || match._[0] === '') {
        delete match._;
      }
    }

    return match;

  } else {
    return path === '/' || path === '' ? {} : {_: [path]};
  }
}
1035960
def taxamatch_preparsed(preparsed_1, preparsed_2)
      result = nil
      if preparsed_1[:uninomial] && preparsed_2[:uninomial]
        result =  match_uninomial(preparsed_1, preparsed_2)
      end
      if preparsed_1[:genus] && preparsed_2[:genus]
        result =  match_multinomial(preparsed_1, preparsed_2)
      end
      if result && result['match']
        result['match'] = match_authors(preparsed_1, preparsed_2) == -1 ?
          false : true
      end
      return result
    end
342409
function matches( entry ){

        var len =       baseName.length;
        return entry[len] === "." && !entry.indexOf( baseName ) && entry.slice( len + 1 ).indexOf( "." ) === -1;
    }
771077
@SuppressWarnings("unchecked")
	public DomainObjectMatch<T> ELEMENTS(TerminalResult...  where) {
		DomainObjectMatch<T> ret;
		// all where expressions have already been added to the astObjects list
		// of the SelectExpression
		SelectExpression<T> se = this.getSelectExpression();
		
		// create match for the true type
		DomainObjectMatch<?> selDom =APIAccess.createDomainObjectMatch(
					se.getStart().getDomainObjectType(),
				se.getQueryExecutor().getDomainObjectMatches().size(),
				se.getQueryExecutor().getMappingInfo());
		handleUnionExpressions(se);
		se.getQueryExecutor().getDomainObjectMatches().add(selDom);
		se.resetAstObjectsContainer();
		se.setEnd(selDom);
		if (se.isReject()) {
			Boolean br_old = QueryRecorder.blockRecording.get();
			try {
				QueryRecorder.blockRecording.set(Boolean.TRUE);
				// remove it from the return statement
				// it is only temporary
				APIAccess.setPartOfReturn(selDom, false);
				AbstractDomainQuery q = se.getDomainQuery();
				DomainObjectMatch<?> rejectDom = InternalAccess.createMatch(q, se.getStart().getDomainObjectType());
				// build complementary set
				q.WHERE(rejectDom).IN(se.getStart());
				q.WHERE(rejectDom).NOT().IN(selDom);
				selDom = rejectDom;
			} finally {
				QueryRecorder.blockRecording.set(br_old);
			}
		}
		if (se.getStartType().equals(DomainObject.class)) // generic domain object match
			ret = APIAccess.createDomainObjectMatch(se.getStartType(), selDom);
		else
			ret = (DomainObjectMatch<T>) selDom;
		Object[] placeHolders = null;
		if (where != null) {
			placeHolders = new QueryRecorder.PlaceHolder[where.length];
			for (int i = 0; i < where.length; i++) {
				placeHolders[i] = QueryRecorder.placeHolder(where[i]);
			}
		}
		DomainObjectMatch<?> delegate = APIAccess.getDelegate(ret);
		DomainObjectMatch<?> match = delegate != null ? delegate : ret;
		if (placeHolders != null)
			QueryRecorder.recordStackedAssignment(this, "ELEMENTS", match, placeHolders);
		else
			QueryRecorder.recordStackedAssignment(this, "ELEMENTS", match);
		return ret;
	}
334392
function Match(path, route, match, query, valueDecoders) {
  this.path = path;
  this.route = route;
  this.match = match;
  this.query = query;

  if (valueDecoders) {
    Object.keys(match || {}).forEach(function(key) {
      if (typeof valueDecoders === 'function') {
        match[key] = valueDecoders(key, match[key]);
        return;
      }
      var fn = valueDecoders.hasOwnProperty(key) && valueDecoders[key];
      if (typeof fn === 'function') {
        match[key] = fn(match[key]);
      }
    });
  }

  this.unmatchedPath = this.match && this.match._ ?
    this.match._[0] :
    null;

  this.matchedPath = this.unmatchedPath ?
    this.path.substring(0, this.path.length - this.unmatchedPath.length) :
    this.path;
}
1170898
function areSameQuery(queryObj1, queryObj2)
{
	var i,j,len,value1,value1clone,value2,value2clone;
	var queryObj1_length = 0;
	
	for (i in queryObj1)
	{
		value1 = hasOwnProperty.call(queryObj1, i);
		value2 = hasOwnProperty.call(queryObj2, i);
		if (value1===false || value2===false || value1!==value2) return false;
		
		value1 = queryObj1[i];
		value2 = queryObj2[i];
		
		// If strings don't match
		if (value1 !== value2)
		{
			// Don't proceed unless both are arrays
			// "?var1=a&var1=b" would've been parsed to { var1: ["a","b"] }
			if (Array.isArray(value1)===false || Array.isArray(value2)===false) return false;
			
			len = value1.length;
			
			if (len !== value2.length) return false;
			
			// Clone so that sort does not mutate input
			// Sort so that values can possibly match at same indexes
			value1clone = value1.slice().sort();
			value2clone = value2.slice().sort();
			
			for (j=0; j<len; j++)
			{
				if (value1clone[j] !== value2clone[j]) return false;
			}
		}
		
		queryObj1_length++;
	}
	
	if (queryObj1_length !== Object.keys(queryObj2).length) return false;
	
	return true;
}
638302
function(item1, item2, query) {
            if (typeof item1 === 'object' && typeof item2 === 'object') {
                query = query || {};
                for (var prop in query) {
                    if (item1[prop] !== item2[prop])
                        return false;
                }
                return true;
            }
            return item1 === item2;
        }