Package org.springframework.data.elasticsearch.core.query

Examples of org.springframework.data.elasticsearch.core.query.Criteria$OrCriteria


      return create(part, iterator);
    }
    PersistentPropertyPath<ElasticsearchPersistentProperty> path = context
        .getPersistentPropertyPath(part.getProperty());
    return base.addCriteria(from(part.getType(),
        new Criteria(path.toDotPath(ElasticsearchPersistentProperty.PropertyToFieldNameConverter.INSTANCE)), iterator));
  }
View Full Code Here


    }
    return query.addSort(sort);
  }

  private Criteria from(Part.Type type, Criteria instance, Iterator<?> parameters) {
    Criteria criteria = instance;
    if (criteria == null) {
      criteria = new Criteria();
    }
    switch (type) {
      case TRUE:
        return criteria.is(true);
      case FALSE:
        return criteria.is(false);
      case SIMPLE_PROPERTY:
        return criteria.is(parameters.next());
      case NEGATING_SIMPLE_PROPERTY:
        return criteria.is(parameters.next()).not();
      case REGEX:
        return criteria.expression(parameters.next().toString());
      case LIKE:
      case STARTING_WITH:
        return criteria.startsWith(parameters.next().toString());
      case ENDING_WITH:
        return criteria.endsWith(parameters.next().toString());
      case CONTAINING:
        return criteria.contains(parameters.next().toString());
      case AFTER:
      case GREATER_THAN:
      case GREATER_THAN_EQUAL:
        return criteria.greaterThanEqual(parameters.next());
      case BEFORE:
      case LESS_THAN:
      case LESS_THAN_EQUAL:
        return criteria.lessThanEqual(parameters.next());
      case BETWEEN:
        return criteria.between(parameters.next(), parameters.next());
      case IN:
        return criteria.in(asArray(parameters.next()));
      case NOT_IN:
        return criteria.in(asArray(parameters.next())).not();
      case WITHIN: {
        Object firstParameter = parameters.next();
        Object secondParameter = parameters.next();

        if (firstParameter instanceof GeoPoint && secondParameter instanceof String)
          return criteria.within((GeoPoint) firstParameter, (String) secondParameter);

        if (firstParameter instanceof Point && secondParameter instanceof Distance)
          return criteria.within((Point) firstParameter, (Distance) secondParameter);

        if (firstParameter instanceof String && secondParameter instanceof String)
          return criteria.within((String) firstParameter, (String) secondParameter);
      }
      case NEAR: {
        Object firstParameter = parameters.next();

        if (firstParameter instanceof GeoBox) {
          return criteria.boundedBy((GeoBox) firstParameter);
        }

        if (firstParameter instanceof Box) {
          return criteria.boundedBy(GeoBox.fromBox((Box) firstParameter));
        }

        Object secondParameter = parameters.next();

        // "near" query can be the same query as the "within" query
        if (firstParameter instanceof GeoPoint && secondParameter instanceof String)
          return criteria.within((GeoPoint) firstParameter, (String) secondParameter);

        if (firstParameter instanceof Point && secondParameter instanceof Distance)
          return criteria.within((Point) firstParameter, (Distance) secondParameter);

        if (firstParameter instanceof String && secondParameter instanceof String)
          return criteria.within((String) firstParameter, (String) secondParameter);
      }

      default:
        throw new InvalidDataAccessApiUsageException("Illegal criteria found '" + type + "'.");
    }
View Full Code Here

    List<QueryBuilder> mustNotQueryBuilderList = new LinkedList<QueryBuilder>();
    List<QueryBuilder> mustQueryBuilderList = new LinkedList<QueryBuilder>();

    ListIterator<Criteria> chainIterator = criteria.getCriteriaChain().listIterator();
    while (chainIterator.hasNext()) {
      Criteria chainedCriteria = chainIterator.next();
      QueryBuilder queryFragmentForCriteria = createQueryFragmentForCriteria(chainedCriteria);

      if (queryFragmentForCriteria != null) {
        if (chainedCriteria.isOr()) {
          shouldQueryBuilderList.add(queryFragmentForCriteria);
        } else if (chainedCriteria.isNegating()) {
          mustNotQueryBuilderList.add(queryFragmentForCriteria);
        } else {
          mustQueryBuilderList.add(queryFragmentForCriteria);
        }
      }
View Full Code Here

    List<QueryBuilder> mustNotQueryBuilderList = new LinkedList<QueryBuilder>();
    List<QueryBuilder> mustQueryBuilderList = new LinkedList<QueryBuilder>();

    ListIterator<Criteria> chainIterator = criteria.getCriteriaChain().listIterator();
    while (chainIterator.hasNext()) {
      Criteria chainedCriteria = chainIterator.next();
      QueryBuilder queryFragmentForCriteria = createQueryFragmentForCriteria(chainedCriteria);

      if (queryFragmentForCriteria != null) {
        if (chainedCriteria.isOr()) {
          shouldQueryBuilderList.add(queryFragmentForCriteria);
        } else if (chainedCriteria.isNegating()) {
          mustNotQueryBuilderList.add(queryFragmentForCriteria);
        } else {
          mustQueryBuilderList.add(queryFragmentForCriteria);
        }
      }
View Full Code Here

    ListIterator<Criteria> chainIterator = criteria.getCriteriaChain().listIterator();

    while (chainIterator.hasNext()) {
      FilterBuilder fb = null;
      Criteria chainedCriteria = chainIterator.next();
      if (chainedCriteria.isOr()) {
        fb = orFilter(createFilterFragmentForCriteria(chainedCriteria).toArray(new FilterBuilder[]{}));
        fbList.add(fb);
      } else if (chainedCriteria.isNegating()) {
        List<FilterBuilder> negationFilters = buildNegationFilter(criteria.getField().getName(), criteria.getFilterCriteriaEntries().iterator());

        if (!negationFilters.isEmpty()) {
          fbList.addAll(negationFilters);
        }
View Full Code Here

    ListIterator<Criteria> chainIterator = criteria.getCriteriaChain().listIterator();

    while (chainIterator.hasNext()) {
      FilterBuilder fb = null;
      Criteria chainedCriteria = chainIterator.next();
      if (chainedCriteria.isOr()) {
        fb = orFilter(createFilterFragmentForCriteria(chainedCriteria).toArray(new FilterBuilder[]{}));
        fbList.add(fb);
      } else if (chainedCriteria.isNegating()) {
        List<FilterBuilder> negationFilters = buildNegationFilter(criteria.getField().getName(), criteria.getFilterCriteriaEntries().iterator());

        if (!negationFilters.isEmpty()) {
          fbList.addAll(negationFilters);
        }
View Full Code Here

    QueryBuilder createQueryFromCriteria(Criteria criteria) {
        BoolQueryBuilder query = boolQuery();

        ListIterator<Criteria> chainIterator = criteria.getCriteriaChain().listIterator();
        while (chainIterator.hasNext()) {
            Criteria chainedCriteria = chainIterator.next();
            if(chainedCriteria.isOr()){
                query.should(createQueryFragmentForCriteria(chainedCriteria));
            }else if(chainedCriteria.isNegating()){
                query.mustNot(createQueryFragmentForCriteria(chainedCriteria));
            }else{
                query.must(createQueryFragmentForCriteria(chainedCriteria));
            }
        }
View Full Code Here

    @Override
    protected CriteriaQuery create(Part part, Iterator<Object> iterator) {
        PersistentPropertyPath<ElasticsearchPersistentProperty> path = context.getPersistentPropertyPath(part.getProperty());
        return new CriteriaQuery(from(part.getType(),
                new Criteria(path.toDotPath(ElasticsearchPersistentProperty.PropertyToFieldNameConverter.INSTANCE)), iterator));
    }
View Full Code Here

        if (base == null) {
            return create(part, iterator);
        }
        PersistentPropertyPath<ElasticsearchPersistentProperty> path = context.getPersistentPropertyPath(part.getProperty());
        return base.addCriteria(from(part.getType(),
                new Criteria(path.toDotPath(ElasticsearchPersistentProperty.PropertyToFieldNameConverter.INSTANCE)), iterator));
    }
View Full Code Here

        return query.addSort(sort);
    }


    private Criteria from(Part.Type type, Criteria instance, Iterator<?> parameters) {
        Criteria criteria = instance;
        if (criteria == null) {
            criteria = new Criteria();
        }
        switch (type) {
            case TRUE:
                return criteria.is(true);
            case FALSE:
                return criteria.is(false);
            case SIMPLE_PROPERTY:
                return criteria.is(parameters.next());
            case NEGATING_SIMPLE_PROPERTY:
                return criteria.is(parameters.next()).not();
            case REGEX:
                return criteria.expression(parameters.next().toString());
            case LIKE:
            case STARTING_WITH:
                return criteria.startsWith(parameters.next().toString());
            case ENDING_WITH:
                return criteria.endsWith(parameters.next().toString());
            case CONTAINING:
                return criteria.contains(parameters.next().toString());
            case AFTER:
            case GREATER_THAN:
            case GREATER_THAN_EQUAL:
                return criteria.greaterThanEqual(parameters.next());
            case BEFORE:
            case LESS_THAN:
            case LESS_THAN_EQUAL:
                return criteria.lessThanEqual(parameters.next());
            case BETWEEN:
                return criteria.between(parameters.next(), parameters.next());
            case IN:
                return criteria.in(asArray(parameters.next()));
            case NOT_IN:
                return criteria.in(asArray(parameters.next())).not();
            default:
                throw new InvalidDataAccessApiUsageException("Illegal criteria found '" + type + "'.");
        }
    }
View Full Code Here

TOP

Related Classes of org.springframework.data.elasticsearch.core.query.Criteria$OrCriteria

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.