Package org.springframework.data.solr.core.query

Examples of org.springframework.data.solr.core.query.Criteria


@NoRepositoryBean
public class SolrProductRepository extends SimpleSolrRepository<Product, String> implements ProductRepository {

  @Override
  public Page<Product> findByPopularity(Integer popularity) {
    Query query = new SimpleQuery(new Criteria(SolrSearchableFields.POPULARITY).is(popularity));
    return getSolrOperations().queryForPage(query, Product.class);
  }
View Full Code Here


    return getSolrOperations().queryForPage(query, Product.class);
  }

  @Override
  public FacetPage<Product> findByNameStartingWithAndFacetOnAvailable(String namePrefix) {
    FacetQuery query = new SimpleFacetQuery(new Criteria(SolrSearchableFields.NAME).startsWith(namePrefix));
    query.setFacetOptions(new FacetOptions(SolrSearchableFields.AVAILABLE));
    return getSolrOperations().queryForFacetPage(query, Product.class);
  }
View Full Code Here

    return getSolrOperations().queryForFacetPage(query, Product.class);
  }

  @Override
  public Page<Product> findByAvailableTrue() {
    Query query = new SimpleQuery(new Criteria(new SimpleField(Criteria.WILDCARD)).expression(Criteria.WILDCARD));
    query.addFilterQuery(new SimpleQuery(new Criteria(SolrSearchableFields.AVAILABLE).is(true)));

    return getSolrOperations().queryForPage(query, Product.class);
  }
View Full Code Here

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

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

        new Criteria(path.toDotPath(SolrPersistentProperty.PropertyToFieldNameConverter.INSTANCE)), iterator));
  }

  @Override
  protected Query or(Query base, Query query) {
    Criteria part = query.getCriteria();
    part.setPartIsOr(true);
    if (part.hasSiblings()) {
      boolean first = true;
      for (Criteria nested : part.getSiblings()) {
        if (first) {
          nested.setPartIsOr(true);
          first = false;
        }
        base.addCriteria(nested);
View Full Code Here

    }
    return query.addSort(sort);
  }

  private Criteria from(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(appendBoostAndGetParameterValue(criteria, parameters));
      case NEGATING_SIMPLE_PROPERTY:
        return criteria.is(appendBoostAndGetParameterValue(criteria, parameters)).not();
      case IS_NULL:
        return criteria.isNull();
      case IS_NOT_NULL:
        return criteria.isNotNull();
      case REGEX:
        return criteria.expression(appendBoostAndGetParameterValue(criteria, parameters).toString());
      case LIKE:
      case STARTING_WITH:
        return criteria.startsWith(asStringArray(appendBoostAndGetParameterValue(criteria, parameters)));
      case NOT_LIKE:
        return criteria.startsWith(asStringArray(appendBoostAndGetParameterValue(criteria, parameters))).not();
      case ENDING_WITH:
        return criteria.endsWith(asStringArray(appendBoostAndGetParameterValue(criteria, parameters)));
      case CONTAINING:
        return criteria.contains(asStringArray(appendBoostAndGetParameterValue(criteria, parameters)));
      case AFTER:
      case GREATER_THAN:
        return criteria.greaterThan(appendBoostAndGetParameterValue(criteria, parameters));
      case GREATER_THAN_EQUAL:
        return criteria.greaterThanEqual(appendBoostAndGetParameterValue(criteria, parameters));
      case BEFORE:
      case LESS_THAN:
        return criteria.lessThan(appendBoostAndGetParameterValue(criteria, parameters));
      case LESS_THAN_EQUAL:
        return criteria.lessThanEqual(appendBoostAndGetParameterValue(criteria, parameters));
      case BETWEEN:
        return criteria.between(appendBoostAndGetParameterValue(criteria, parameters),
            appendBoostAndGetParameterValue(criteria, parameters));
      case IN:
        return criteria.in(asArray(appendBoostAndGetParameterValue(criteria, parameters)));
      case NOT_IN:
        return criteria.in(asArray(appendBoostAndGetParameterValue(criteria, parameters))).not();
      case NEAR:
        return createNearCriteria(parameters, criteria);
      case WITHIN:
        return criteria.within((Point) getBindableValue((BindableSolrParameter) parameters.next()),
            (Distance) getBindableValue((BindableSolrParameter) parameters.next()));
      default:
        throw new InvalidDataAccessApiUsageException("Illegal criteria found '" + type + "'.");
    }
  }
View Full Code Here

   *
   * @param criteria
   * @return
   */
  protected String createQueryFragmentForCriteria(Criteria part) {
    Criteria criteria = (Criteria) part;
    StringBuilder queryFragment = new StringBuilder();
    boolean singeEntryCriteria = (criteria.getPredicates().size() == 1);
    if (criteria instanceof QueryStringHolder) {
      return ((QueryStringHolder) criteria).getQueryString();
    }

    String fieldName = getNullsafeFieldName(criteria.getField());
    if (criteria.isNegating()) {
      fieldName = NOT + fieldName;
    }
    if (!StringUtils.isEmpty(fieldName) && !containsFunctionCriteria(criteria.getPredicates())) {
      queryFragment.append(fieldName);
      queryFragment.append(DELIMINATOR);
    }

    // no criteria given is defaulted to not null
    if (criteria.getPredicates().isEmpty()) {
      queryFragment.append("[* TO *]");
      return queryFragment.toString();
    }

    if (!singeEntryCriteria) {
      queryFragment.append("(");
    }

    CriteriaQueryStringValueProvider valueProvider = new CriteriaQueryStringValueProvider(criteria);
    while (valueProvider.hasNext()) {
      queryFragment.append(valueProvider.next());
      if (valueProvider.hasNext()) {
        queryFragment.append(CRITERIA_VALUE_SEPERATOR);
      }
    }

    if (!singeEntryCriteria) {
      queryFragment.append(")");
    }
    if (!Float.isNaN(criteria.getBoost())) {
      queryFragment.append(BOOST + criteria.getBoost());
    }

    return queryFragment.toString();
  }
View Full Code Here

    this.setEntityClass(entityClass);
  }

  @Override
  public T findOne(ID id) {
    return getSolrOperations().queryForObject(new SimpleQuery(new Criteria(this.idFieldName).is(id)), getEntityClass());
  }
View Full Code Here

  }

  @Override
  public Page<T> findAll(Pageable pageable) {
    return getSolrOperations().queryForPage(
        new SimpleQuery(new Criteria(Criteria.WILDCARD).expression(Criteria.WILDCARD)).setPageRequest(pageable),
        getEntityClass());
  }
View Full Code Here

TOP

Related Classes of org.springframework.data.solr.core.query.Criteria

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.