Apply the Query Filters.

@return
555357
private function applyQueryFilters()
    {
        if (is_array($this->queryFilter())) {
            $this->createQueryFilter();
        } else {
            $this->queryFilter();
        }

        $this->queryFilterRequest();
    }
926085
public function apply()
    {
        $records = $this->getLiveRecords();
        
        if ($ids = $this->getDraftIds()) {
            $records = $records->exclude('ID', $ids);
        }
        
        return $records;
    }
301072
def apply_filters(o)
      @filters.keys.find_all{|type| Splib.type_of?(o, type)}.each do |type|
        @filters[type].each_pair do |k,v|
          begin
            case k
            when :filters
              v.each{|f|o = f.filter(o)}
            when :procs
              v.each{|pr|o = pr.call(o)}
            end
          rescue ArgumentError
            # ignore this
          end
        end
      end
      o
    end
643710
private function getSearchQuery()
    {
        $queries = [];

        foreach ($this->queryProviders as $queryProvider) {
            $queries[] = $queryProvider->getQuery();
        }

        return array_filter($queries);
    }
691449
public function apply_filters() {
		$args = func_get_args();
		$tag  = current( array_splice( $args, 1, 1 ) );
		return apply_filters_ref_array( $tag, $args );
	}
1104786
private <T, R> void applyPredicates(JoinerQuery<T, R> request, JPAQuery query, Set<Path<?>> usedAliases, List<JoinDescription> joins) {
        if (request.getWhere() != null) {
            Predicate where = predicateAliasResolver.resolvePredicate(request.getWhere(), joins, usedAliases);
            checkAliasesArePresent(where, usedAliases);
            query.where(where);
        }
        if (request.getGroupBy() != null) {
            Map<AnnotatedElement, List<JoinDescription>> grouped = joins.stream()
                    .collect(Collectors.groupingBy(j -> j.getOriginalAlias().getAnnotatedElement()));
            Path<?> grouping = predicateAliasResolver.resolvePath(request.getGroupBy(), grouped, usedAliases);
            checkAliasesArePresent(grouping, usedAliases);
            query.groupBy(grouping);
        }
        if (request.getHaving() != null) {
            Predicate having = predicateAliasResolver.resolvePredicate(request.getHaving(), joins, usedAliases);
            checkAliasesArePresent(having, usedAliases);
            query.having(having);
        }
    }
734418
public java.util.List<ParameterStringFilter> getParameterFilters() {
        if (parameterFilters == null) {
            parameterFilters = new com.amazonaws.internal.SdkInternalList<ParameterStringFilter>();
        }
        return parameterFilters;
    }
371154
public void setFilters(java.util.Collection<Filter> filters) {
        if (filters == null) {
            this.filters = null;
            return;
        }

        this.filters = new java.util.ArrayList<Filter>(filters);
    }
823640
public function apply()
    {
        $records = $this->getDraftRecords();
        
        if ($ids = $this->getLiveIds()) {
            $records = $records->exclude('ID', $ids);
        }
        
        return $records;
    }
850294
private function applyFilters($filters = [], $returnCount = false)
    {
        $result = null;
        // Convert our filters into a query.
        if ($filters) {
            $alias = $this->getTableAlias();
            $query = $this->slaveQueryBuilder();
            if ($returnCount) {
                $query->select('COUNT(*)');
            } else {
                // Selecting only the id and contact_id for covering index benefits.
                $query->select($alias.'.id, '.$alias.'.contact_id');
                $query->setMaxResults(1);
            }
            $query->from(MAUTIC_TABLE_PREFIX.$this->getTableName(), $alias);

            foreach ($filters as $k => $set) {
                // Expect orx, anx, or neither.
                if (isset($set['orx'])) {
                    if (!empty($set['orx'])) {
                        $expr = $query->expr()->orX();
                    }
                    $properties = $set['orx'];
                } elseif (isset($set['andx'])) {
                    if (!empty($set['andx'])) {
                        $expr = $query->expr()->andX();
                    }
                    $properties = $set['andx'];
                } else {
                    if (!isset($expr)) {
                        $expr = $query->expr()->andX();
                    }
                    $properties = $set;
                }
                if (isset($expr) && !empty($properties)) {
                    foreach ($properties as $property => $value) {
                        if (is_array($value)) {
                            $expr->add(
                                $query->expr()->andX(
                                    $query->expr()->isNotNull($alias.'.'.$property),
                                    $query->expr()->in($alias.'.'.$property, $value)
                                )
                            );
                        } elseif (is_int($value) || is_string($value)) {
                            if (!empty($value)) {
                                $expr->add(
                                    $query->expr()->andX(
                                        $query->expr()->isNotNull($alias.'.'.$property),
                                        $query->expr()->eq($alias.'.'.$property, ':'.$property.$k)
                                    )
                                );
                            } else {
                                $expr->add(
                                    $query->expr()->eq($alias.'.'.$property, ':'.$property.$k)
                                );
                            }
                            if (in_array($property, ['category_id', 'contact_id', 'campaign_id', 'contactclient_id'])) {
                                // Explicit integers for faster queries.
                                $query->setParameter($property.$k, (int) $value, \PDO::PARAM_INT);
                            } else {
                                $query->setParameter($property.$k, $value);
                            }
                        }
                    }
                }
                if (isset($set['exclusive_expire_date'])) {
                    // Expiration/Exclusions will require an extra outer AND expression.
                    if (!isset($exprOuter)) {
                        $exprOuter  = $query->expr()->orX();
                        $expireDate = $set['exclusive_expire_date'];
                    }
                    if (isset($expr)) {
                        $exprOuter->add(
                            $query->expr()->orX($expr)
                        );
                    }
                } elseif (isset($set['contactclient_id']) && isset($set['date_added'])) {
                    $query->add(
                        'where',
                        $query->expr()->andX(
                            $query->expr()->eq($alias.'.contactclient_id', ':contactClientId'.$k),
                            $query->expr()->gte($alias.'.date_added', 'FROM_UNIXTIME(:dateAdded'.$k.')'),
                            (isset($expr) ? $expr : null)
                        )
                    );
                    $query->setParameter('contactClientId'.$k, (int) $set['contactclient_id'], \PDO::PARAM_INT);
                    $query->setParameter('dateAdded'.$k, $set['date_added']);
                }
            }
            // Expiration can always be applied globally.
            if (isset($exprOuter) && isset($expireDate)) {
                $query->add(
                    'where',
                    $query->expr()->andX(
                        $query->expr()->isNotNull($alias.'.exclusive_expire_date'),
                        $query->expr()->gte($alias.'.exclusive_expire_date', 'FROM_UNIXTIME(:exclusiveExpireDate)'),
                        $exprOuter
                    )
                );
                $query->setParameter('exclusiveExpireDate', $expireDate);
            }

            $result = $query->execute()->fetch();
            if ($returnCount) {
                $result = intval(reset($result));
            }
        }

        return $result;
    }
947679
private static Map<String, QueryBuilder> buildFilters(RuleQuery query) {
    Map<String, QueryBuilder> filters = new HashMap<>();

    /* Add enforced filter on main type Rule */
    filters.put(
      FIELD_INDEX_TYPE,
      boolQuery().must(QueryBuilders.termsQuery(FIELD_INDEX_TYPE, TYPE_RULE.getType())));

    /* Add enforced filter on rules that are REMOVED */
    filters.put(FIELD_RULE_STATUS,
      boolQuery().mustNot(
        QueryBuilders.termQuery(FIELD_RULE_STATUS,
          RuleStatus.REMOVED.toString())));

    if (StringUtils.isNotEmpty(query.getInternalKey())) {
      filters.put(FIELD_RULE_INTERNAL_KEY,
        QueryBuilders.termQuery(FIELD_RULE_INTERNAL_KEY, query.getInternalKey()));
    }

    if (StringUtils.isNotEmpty(query.getRuleKey())) {
      filters.put(FIELD_RULE_RULE_KEY,
        QueryBuilders.termQuery(FIELD_RULE_RULE_KEY, query.getRuleKey()));
    }

    if (isNotEmpty(query.getLanguages())) {
      filters.put(FIELD_RULE_LANGUAGE,
        QueryBuilders.termsQuery(FIELD_RULE_LANGUAGE, query.getLanguages()));
    }

    if (isNotEmpty(query.getRepositories())) {
      filters.put(FIELD_RULE_REPOSITORY,
        QueryBuilders.termsQuery(FIELD_RULE_REPOSITORY, query.getRepositories()));
    }

    if (isNotEmpty(query.getSeverities())) {
      filters.put(FIELD_RULE_SEVERITY,
        QueryBuilders.termsQuery(FIELD_RULE_SEVERITY, query.getSeverities()));
    }

    if (StringUtils.isNotEmpty(query.getKey())) {
      filters.put(FIELD_RULE_KEY,
        QueryBuilders.termQuery(FIELD_RULE_KEY, query.getKey()));
    }

    if (isNotEmpty(query.getTags())) {
      filters.put(FIELD_RULE_EXTENSION_TAGS,
        buildTagsFilter(query.getTags(), query.getOrganization()));
    }

    Collection<RuleType> types = query.getTypes();
    if (isNotEmpty(types)) {
      List<String> typeNames = types.stream().map(RuleType::toString).collect(MoreCollectors.toList());
      filters.put(FIELD_RULE_TYPE,
        QueryBuilders.termsQuery(FIELD_RULE_TYPE, typeNames));
    }

    if (query.getAvailableSinceLong() != null) {
      filters.put("availableSince", QueryBuilders.rangeQuery(FIELD_RULE_CREATED_AT)
        .gte(query.getAvailableSinceLong()));
    }

    if (isNotEmpty(query.getStatuses())) {
      Collection<String> stringStatus = new ArrayList<>();
      for (RuleStatus status : query.getStatuses()) {
        stringStatus.add(status.name());
      }
      filters.put(FIELD_RULE_STATUS,
        QueryBuilders.termsQuery(FIELD_RULE_STATUS, stringStatus));
    }

    Boolean isTemplate = query.isTemplate();
    if (isTemplate != null) {
      filters.put(FIELD_RULE_IS_TEMPLATE,
        QueryBuilders.termQuery(FIELD_RULE_IS_TEMPLATE, Boolean.toString(isTemplate)));
    }

    boolean includeExternal = query.includeExternal();
    if (!includeExternal) {
      filters.put(FIELD_RULE_IS_EXTERNAL,
        QueryBuilders.termQuery(FIELD_RULE_IS_EXTERNAL, false));
    }

    String template = query.templateKey();
    if (template != null) {
      filters.put(FIELD_RULE_TEMPLATE_KEY,
        QueryBuilders.termQuery(FIELD_RULE_TEMPLATE_KEY, template));
    }

    /* Implementation of activation query */
    QProfileDto profile = query.getQProfile();
    if (query.getActivation() != null && profile != null) {
      QueryBuilder childQuery = buildActivationFilter(query, profile);

      if (TRUE.equals(query.getActivation())) {
        filters.put("activation",
          JoinQueryBuilders.hasChildQuery(TYPE_ACTIVE_RULE.getName(),
            childQuery, ScoreMode.None));
      } else if (FALSE.equals(query.getActivation())) {
        filters.put("activation",
          boolQuery().mustNot(
            JoinQueryBuilders.hasChildQuery(TYPE_ACTIVE_RULE.getName(),
              childQuery, ScoreMode.None)));
      }
      QProfileDto compareToQProfile = query.getCompareToQProfile();
      if (compareToQProfile != null) {
        filters.put("comparison",
          JoinQueryBuilders.hasChildQuery(
            TYPE_ACTIVE_RULE.getName(),
            boolQuery().must(QueryBuilders.termQuery(FIELD_ACTIVE_RULE_PROFILE_UUID, compareToQProfile.getRulesProfileUuid())),
            ScoreMode.None));
      }
    }

    return filters;
  }
686548
@Override
    public List<FILTERTYPE> getAllFilter() {

        final List<FILTERTYPE> list = new ArrayList<FILTERTYPE>();
        final List<Node> nodeList = model.get("filter");
        for (final Node node : nodeList) {
            final FILTERTYPE filter = this.createNewFilterViewForModel(node);
            list.add(filter);
        }

        return list;
    }
378371
def applyQuery( self ):
        
        query = Q.fromString(nativestring(self.uiQueryTXT.text()))
        self.setQuery(query)
        self.uiQueryTXT.setText('')
1006853
public List<OperationResponse> apply(List<Operation> operations, QueryContext queryContext) {
		checkAccess(operations, queryContext);
		enrichTypeIdInformation(operations);

		List<OrderedOperation> orderedOperations = orderStrategy.order(operations);

		DefaultOperationFilterChain chain = new DefaultOperationFilterChain();
		return chain.doFilter(new DefaultOperationFilterContext(orderedOperations));
	}
547032
public java.util.List<SubscriptionFilter> getSubscriptionFilters() {
        if (subscriptionFilters == null) {
            subscriptionFilters = new com.amazonaws.internal.SdkInternalList<SubscriptionFilter>();
        }
        return subscriptionFilters;
    }
260560
private function applyFilters()
    {
        // Only apply filters if this is mutable.
        if ($this->isImmutable) {
            return;
        }

        // Reset to original items before filtering.
        $this->exchangeArray($this->originalItems);

        // Apply filter to items.
        if (count($this->filters) > 0) {
            $filtered_array = array_filter(
                $this->getArrayCopy(),
                function ($item) {
                    foreach ($this->filters as $callback) {
                        if (call_user_func($callback, $item) === true) {
                            return true;
                        }
                    }
                    return false;
                }
            );
            $this->exchangeArray(array_values($filtered_array));
        }

        // Filter nested items.
        foreach ($this->getArrayCopy() as $item) {
            if ($item instanceof MultiValue) {
                foreach ($this->filters as $callback) {
                    $item->filter($callback);
                }
            }
        }
    }
939060
public CmsRelationFilter filterStrong() {

        CmsRelationFilter filter = (CmsRelationFilter)clone();
        if (filter.m_types.isEmpty()) {
            filter.m_types.addAll(CmsRelationType.getAllStrong());
        } else {
            filter.m_types = new HashSet<CmsRelationType>(CmsRelationType.filterStrong(filter.m_types));
        }
        return filter;
    }