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

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


@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().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
  public Object execute(Object[] parameters) {
    SolrParameterAccessor accessor = new SolrParametersParameterAccessor(solrQueryMethod, parameters);

    Query query = createQuery(accessor);
    decorateWithFilterQuery(query, accessor);
    setDefaultQueryOperatorIfDefined(query);
    setAllowedQueryExeutionTime(query);
    setDefTypeIfDefined(query);
    setRequestHandlerIfDefined(query);

    if (solrQueryMethod.hasStatsDefinition()) {
      query.setStatsOptions(extractStatsOptions(solrQueryMethod, accessor));
    }

    if (isCountQuery() && isDeleteQuery()) {
      throw new InvalidDataAccessApiUsageException("Cannot execute 'delete' and 'count' at the same time.");
    }
View Full Code Here

    private Object countOrGetDocumentsForDelete(Query query) {

      Object result = null;

      if (solrQueryMethod.isCollectionQuery()) {
        Query clone = SimpleQuery.fromQuery(query);
        result = solrOperations.queryForPage(clone.setPageRequest(new SolrPageRequest(0, Integer.MAX_VALUE)),
            solrQueryMethod.getEntityInformation().getJavaType()).getContent();
      }

      if (ClassUtils.isAssignable(Number.class, solrQueryMethod.getReturnedObjectType())) {
        result = solrOperations.count(query);
View Full Code Here

    return tree;
  }

  @Override
  protected Query createQuery(SolrParameterAccessor parameterAccessor) {
    Query query = new SolrQueryCreator(tree, parameterAccessor, mappingContext).createQuery();
    appendProjection(query);
    return query;
  }
View Full Code Here

  @Test
  public void testCreateFindBySingleCriteria() throws NoSuchMethodException, SecurityException {
    Method method = SampleRepository.class.getMethod("findByPopularity", Integer.class);

    Query query = createQueryForMethodWithArgs(method, new Object[] { 100 });
    Assert.assertEquals("popularity:100", queryParser.getQueryString(query));
  }
View Full Code Here

  @Test
  public void testCreateFindByNotCriteria() throws NoSuchMethodException, SecurityException {
    Method method = SampleRepository.class.getMethod("findByPopularityIsNot", Integer.class);

    Query query = createQueryForMethodWithArgs(method, new Object[] { 100 });
    Assert.assertEquals("-popularity:100", queryParser.getQueryString(query));
  }
View Full Code Here

  @Test
  public void testCreateFindByNotNullCriteria() throws NoSuchMethodException, SecurityException {
    Method method = SampleRepository.class.getMethod("findByPopularityIsNotNull");

    Query query = createQueryForMethodWithArgs(method, new Object[] {});
    Assert.assertEquals("popularity:[* TO *]", queryParser.getQueryString(query));
  }
View Full Code Here

  @Test
  public void testCreateFindByNullCriteria() throws NoSuchMethodException, SecurityException {
    Method method = SampleRepository.class.getMethod("findByPopularityIsNull");

    Query query = createQueryForMethodWithArgs(method, new Object[] {});
    Assert.assertEquals("-popularity:[* TO *]", queryParser.getQueryString(query));
  }
View Full Code Here

  @Test
  public void testCreateFindByAndQuery() throws NoSuchMethodException, SecurityException {
    Method method = SampleRepository.class.getMethod("findByPopularityAndPrice", Integer.class, Float.class);

    Query query = createQueryForMethodWithArgs(method, new Object[] { 100, 200f });
    Assert.assertEquals("popularity:100 AND price:200.0", queryParser.getQueryString(query));
  }
View Full Code Here

TOP

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

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.