Compilation involves altering the previous entityfilter so that it receives the
limit arguments
547742
function compile(context, commands) {
    let ii, cmd, limitOptions;

    // log.debug('limit: in-compile cmds:', commands);

    // look for the limit commands within the commands
    for (ii = commands.length - 1; ii >= 0; ii--) {
        cmd = commands[ii];
        if (cmd[0] === LIMIT) {
            // cmdLimit = cmd;
            limitOptions = {
                offset: context.valueOf(cmd[2]),
                limit: context.valueOf(cmd[1])
            };
            commands.splice(ii, 1);
        } else if (limitOptions && cmd[0] === ENTITY_FILTER) {
            // set the options object of the entityFilter command
            if (limitOptions) {
                cmd[3] = { ...cmd[3], ...limitOptions };
            }
            limitOptions = null;
        }
    }

    // if we still have an open limit and no entity filter was found, add one
    if (limitOptions) {
        commands.unshift([ENTITY_FILTER, null, null, limitOptions]);
    }

    return commands;
}
852096
private static void appendOptionalMatchOwnerEmbeddedNodes(StringBuilder queryBuilder) {
		queryBuilder.append( " OPTIONAL MATCH (" );
		queryBuilder.append( ENTITY_ALIAS );
		queryBuilder.append( ") -[" );
		queryBuilder.append( FIRST_EMBEDDED_REL_ALIAS );
		queryBuilder.append( "]->(" );
		queryBuilder.append( FIRST_EMBEDDED_ALIAS );
		queryBuilder.append( ":" );
		queryBuilder.append( NodeLabel.EMBEDDED );
		queryBuilder.append( ")" );
		queryBuilder.append( " OPTIONAL MATCH (" );
		queryBuilder.append( FIRST_EMBEDDED_ALIAS );
		queryBuilder.append( ")-[" );
		queryBuilder.append( EMBEDDED_REL_ALIAS );
		queryBuilder.append( "*]->(" );
		queryBuilder.append( EMBEDDED_ALIAS );
		queryBuilder.append( ":" );
		queryBuilder.append( NodeLabel.EMBEDDED );
		queryBuilder.append( ")" );
	}
456197
def Compile(self, filter_implemention):
    """"""
    return self.operator_method(self.attribute_obj, filter_implemention,
                                *self.args)
422115
function normFilter(model, filter, fieldName) {
  if (!filter) return null;

  let result = {},
    fields = model.def.fields;
  for (const key in filter) {
    if (key === '$and' || key === '$or') { // {$and:[]}, {$or: []}
      const subfilters = [];
      for (const j in filter[key]) {
        const sub = normFilter(model, filter[key][j]);
        if (!sub) continue;
        subfilters.push(sub);
      }
      if (subfilters.length > 0) result[key] = subfilters;
      continue;
    }
    if (key.charAt(0) === '$') { // key is an operator, {op: value}
      if (!fieldName) {
        throw new QueryError(model.name, 'no field for operator %s in filter', key);
      }
      if (!fields[fieldName]) {
        throw new QueryError(model.name, 'nonexistent field %s in filter', fieldName);
      }
      result[key] = fields[fieldName].normalize(filter[key], { query: true });
      continue;
    }

    // key is a field, {field: value}, {field: {op: value, ...}}
    fieldName = key;
    const field = fields[key];
    if (!field) throw new QueryError(model.name, 'nonexistent field %s in filter', key);
    if (field.props.filterRedirect) {
      const proxyFields = field.props.filterRedirect.replace(/\s+/g, '').split(',');
      const proxyFilter = { $or: [] };
      for (const pi in proxyFields) {
        const proxyFieldName = proxyFields[pi];
        const fieldProxyFilter = {};
        fieldProxyFilter[proxyFieldName] = filter[key];
        proxyFilter.$or.push(fieldProxyFilter);
      }
      Object.assign(result, normFilter(model, proxyFilter));
      continue;
    }

    // {field: {op: value, ...}}
    if (util.isPlainObject(filter[key])) {
      result[fieldName] = normFilter(model, filter[key], fieldName);
      continue;
    }

    // {field: value}, value is not string
    let value = filter[key];
    if (typeof value !== 'string') { // array, date, int, float, bool, etc
      result[fieldName] = field.normalize(value, { query: true });
      continue;
    }

    // {field: value}, value is a plain string
    value = value.trim();
    if (!(value.substring(0, 1) === '{' && value.substr(-1) === '}')) {
      result[fieldName] = field.normalize(value, { query: true });
      continue;
    }

    // {field: value}, value is string and may contain a json object which is a query filter too
    const jsonExpr = null;
    try {
      eval('jsonExpr = '+value);//eslint-disable-line
    } catch (e) {}// eslint-disable-line no-empty
    if (!jsonExpr) { // parse fails, treat as plain string
      result[fieldName] = field.normalize(value, { query: true });
    } else {
      const jsonFilter = {};
      for (const jk in jsonExpr) {
        if (jk.charAt(0) === '$') { // expand {op:val} to {field:{op: val}}
          jsonFilter[fieldName] = {};
          jsonFilter[fieldName][jk] = jsonExpr[jk];
        } else { // {field: value}
          jsonFilter[jk] = jsonExpr[jk];
        }
      }
      result = Object.assign(result, normFilter(model, jsonFilter, fieldName));
    }
  }

  if (util.isEmptyObject(result)) return null;
  return result;
}
1067632
async def filter_by(cls, db, offset=None, limit=None, **kwargs):
        
        if limit and type(limit) is not int:
            raise InvalidQuery('If limit is supplied it must be an int')
        if offset and type(offset) is not int:
            raise InvalidQuery('If offset is supplied it must be an int')

        ids_to_iterate = await cls._get_ids_filter_by(db, **kwargs)
        if offset:
            # Using offset without order_by is pretty strange, but allowed
            if limit:
                ids_to_iterate = ids_to_iterate[offset:offset+limit]
            else:
                ids_to_iterate = ids_to_iterate[offset:]
        elif limit:
            ids_to_iterate = ids_to_iterate[:limit]

        for key in ids_to_iterate:
            yield await cls.load(db, key)
321998
private void expandEntity(EntityDecl ed, boolean allowExt)
        throws XMLStreamException
    {
        String id = ed.getName();

        /* Very first thing; we can immediately check if expanding
         * this entity would result in infinite recursion:
         */
        if (mInput.isOrIsExpandedFrom(id)) {
            throwRecursionError(id);
        }

        /* Should not refer unparsed entities from attribute values
         * or text content (except via notation mechanism, but that's
         * not parsed here)
         */
        if (!ed.isParsed()) {
            throwParseError("Illegal reference to unparsed external entity \"{0}\"", id, null);
        }

        // 28-Jun-2004, TSa: Do we support external entity expansion?
        boolean isExt = ed.isExternal();
        if (isExt) {
            if (!allowExt) { // never ok in attribute value...
                throwParseError("Encountered a reference to external parsed entity \"{0}\" when expanding attribute value: not legal as per XML 1.0/1.1 #3.1", id, null);
            }
            if (!mConfig.willSupportExternalEntities()) {
                throwParseError("Encountered a reference to external entity \"{0}\", but stream reader has feature \"{1}\" disabled",
                                id, XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES);
            }
        }
        verifyLimit("Maximum entity expansion count", mConfig.getMaxEntityCount(), ++mEntityExpansionCount);
        // First, let's give current context chance to save its stuff
        WstxInputSource oldInput = mInput;
        oldInput.saveContext(this);
        WstxInputSource newInput = null;
        try {
            newInput = ed.expand(oldInput, mEntityResolver, mConfig, mDocXmlVersion);
        } catch (FileNotFoundException fex) {
            /* Let's catch and rethrow this just so we get more meaningful
             * description (with input source position etc)
             */
            throwParseError("(was {0}) {1}", fex.getClass().getName(), fex.getMessage());
        } catch (IOException ioe) {
            throw constructFromIOE(ioe);
        }
        /* And then we'll need to make sure new input comes from the new
         * input source
         */
        initInputSource(newInput, isExt, id);
    }
958232
def Compile(self, filter_implemention):
    """"""
    operator = self.operator.lower()
    if operator == "and" or operator == "&&":
      method = "AndFilter"
    elif operator == "or" or operator == "||":
      method = "OrFilter"
    else:
      raise ParseError("Invalid binary operator %s" % operator)

    args = [x.Compile(filter_implemention) for x in self.args]
    return filter_implemention.FILTERS[method](arguments=args)
465966
def Compile(self, filter_implementation):
    """"""
    operator = self.operator.lower()
    if operator in ('and', '&&'):
      method = 'AndFilter'
    elif operator in ('or', '||'):
      method = 'OrFilter'
    else:
      raise errors.ParseError(
          'Invalid binary operator {0:s}.'.format(operator))

    args = [x.Compile(filter_implementation) for x in self.args]
    return filter_implementation.FILTERS[method](arguments=args)
748873
private EntityDocumentProcessor filterEntityDocumentProcessor(
			EntityDocumentProcessor processor) {
		if (this.filter.getPropertyFilter() == null
				&& this.filter.getSiteLinkFilter() == null
				&& this.filter.getLanguageFilter() == null) {
			return processor;
		} else {
			return new EntityDocumentProcessorFilter(
					processor, this.filter);
		}
	}
249187
function _valuefyArgs(args, lib) {
    for (var i = 0; i < args.length; i++) {
        args[i] = _entityToValue(args[i], lib);
    }
}
340406
private void add(MethodFilter filter) {
        switch(operator) {
        case NOT:
            filters.add(new NegationMethodFilter(filter));
            operator = Operator.NONE;
            break;
        case OR:
            filters.set(filters.size() - 1, 
                        new OrMethodFilter(filters.get(filters.size() - 1), filter));
            operator = Operator.NONE;
            break;
        default:
            filters.add(filter);
            break;
        }
    }
737164
private void processPropertyFilter(final StringBuilder whereBuilder,
                                       final List<Object> paramList, final PropertyFilter propertyFilter) throws RepositoryException {
        String filterOperator;

        switch (propertyFilter.getOperator()) {
            case EQUAL:
                filterOperator = "=";

                break;
            case GREATER_THAN:
                filterOperator = ">";

                break;
            case GREATER_THAN_OR_EQUAL:
                filterOperator = ">=";

                break;
            case LESS_THAN:
                filterOperator = "<";

                break;
            case LESS_THAN_OR_EQUAL:
                filterOperator = "<=";

                break;
            case NOT_EQUAL:
                filterOperator = "!=";

                break;
            case IN:
                filterOperator = "IN";

                break;
            case LIKE:
                filterOperator = "LIKE";

                break;
            case NOT_LIKE:
                filterOperator = "NOT LIKE";

                break;
            default:
                throw new RepositoryException("Unsupported filter operator [" + propertyFilter.getOperator() + "]");
        }

        if (FilterOperator.IN != propertyFilter.getOperator()) {
            whereBuilder.append(propertyFilter.getKey()).append(" ").append(filterOperator).append(" ?");
            paramList.add(propertyFilter.getValue());
        } else {
            final Collection<Object> objects = (Collection<Object>) propertyFilter.getValue();

            boolean isSubFist = true;

            if (objects != null && !objects.isEmpty()) {
                whereBuilder.append(propertyFilter.getKey()).append(" IN ");

                final Iterator<Object> obs = objects.iterator();

                while (obs.hasNext()) {
                    if (isSubFist) {
                        whereBuilder.append("(");
                        isSubFist = false;
                    } else {
                        whereBuilder.append(",");
                    }
                    whereBuilder.append("?");
                    paramList.add(obs.next());

                    if (!obs.hasNext()) {
                        whereBuilder.append(") ");
                    }
                }
            } else { // in () => 1!=1
                whereBuilder.append("1 != 1");
            }
        }
    }
722616
function(filterName, input, args) {
            var self            = this,
                hooks           = self.constructor.filters[filterName],
                output          = input,
                extensionName   = '';

            if (!hooks || h.isEmptyObject(hooks)) return output;

            args = args || [];

            for (extensionName in hooks) {
                args = h.arrayFromList(args);

                args.unshift(output);

                output = hooks[extensionName].apply(self, args);
            }

            return output;
        }
852764
def Compile(self, filter_implementation):
    """"""
    operator = self.operator.lower()
    if operator in ('and', '&&'):
      method = 'AndFilter'
    elif operator in ('or', '||'):
      method = 'OrFilter'
    else:
      raise errors.ParseError(
          'Invalid binary operator {0:s}'.format(operator))

    args = [x.Compile(filter_implementation) for x in self.args]
    return getattr(filter_implementation, method)(*args)
644566
private function resolveFilters(array $filters, array $propertyParameter, array $options, $limit, $page, $pageSize)
    {
        $filters['dataSource'] = $this->nodeHelper->getBaseSnippetUuid(
            array_key_exists('type', $propertyParameter) ? $propertyParameter['type'] : null
        );
        $filters['includeSubFolders'] = true;

        $properties = array_key_exists('properties', $propertyParameter)
            ? $propertyParameter['properties']->getValue() : [];

        $excluded = [];

        if (array_key_exists('excluded', $filters) && is_array($filters['excluded'])) {
            $excluded = $filters['excluded'];
        }

        if (array_key_exists('exclude_duplicates', $propertyParameter)
            && $propertyParameter['exclude_duplicates']->getValue()
        ) {
            $excluded = array_merge($excluded, $this->referenceStore->getAll());
        }

        $this->snippetQueryBuilder->init(
            [
                'config' => $filters,
                'properties' => $properties,
                'excluded' => $excluded,
            ]
        );

        $loadLimit = $limit;
        $offset = null;

        if (null !== $pageSize) {
            $offset = ($page - 1) * $pageSize;

            $position = $pageSize * $page;
            if (null !== $limit && $position >= $limit) {
                $pageSize = $limit - $offset;
                $loadLimit = $pageSize;
            } else {
                $loadLimit = $pageSize + 1;
            }
        }

        $items = $this->contentQueryExecutor->execute(
            $options['webspaceKey'],
            [$options['locale']],
            $this->snippetQueryBuilder,
            true,
            -1,
            $loadLimit,
            $offset
        );

        $hasNextPage = false;
        if (null !== $pageSize) {
            $hasNextPage = (count($items) > $pageSize);
            $items = array_splice($items, 0, $pageSize);
        }

        return [$items, $hasNextPage];
    }
1233937
def apply(filter):
    
    def decorator(callable):
        return lambda *args, **kwargs: filter(callable(*args, **kwargs))
    return decorator
1282305
private void onLimit(StringBuilder builder) {
        if (Integer.MAX_VALUE != maxResult) {
            builder.append(CQLTranslator.LIMIT);
            builder.append(isSingleResult ? 1 : this.maxResult);
        }
    }