コード例 #1
0
  @Test
  public void testCreateQueryWithLikeNotClause() throws NoSuchMethodException, SecurityException {
    Method method = SampleRepository.class.getMethod("findByTitleNotLike", String.class);

    Query query = createQueryForMethodWithArgs(method, new Object[] {"j73x73r"});
    Assert.assertEquals("-title:j73x73r*", queryParser.getQueryString(query));
  }
コード例 #2
0
  @Test
  public void testCreateQueryWithLessThanClause() throws NoSuchMethodException, SecurityException {
    Method method = SampleRepository.class.getMethod("findByPriceLessThan", Float.class);

    Query query = createQueryForMethodWithArgs(method, new Object[] {100f});
    Assert.assertEquals("price:[* TO 100.0}", queryParser.getQueryString(query));
  }
コード例 #3
0
  @Test
  public void testCreateQueryWithFalseClause() throws NoSuchMethodException, SecurityException {
    Method method = SampleRepository.class.getMethod("findByAvailableFalse");

    Query query = createQueryForMethodWithArgs(method, new Object[] {});
    Assert.assertEquals("inStock:false", queryParser.getQueryString(query));
  }
コード例 #4
0
  @Test
  public void testCreateQueryWithNotInClause() throws NoSuchMethodException, SecurityException {
    Method method = SampleRepository.class.getMethod("findByPopularityNotIn", Integer[].class);

    Query query = createQueryForMethodWithArgs(method, new Object[] {new Object[] {1, 2, 3}});
    Assert.assertEquals("-popularity:(1 2 3)", queryParser.getQueryString(query));
  }
コード例 #5
0
  @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));
  }
コード例 #6
0
  @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));
  }
コード例 #7
0
  @Test
  public void testCreateQueryWithRegexClause() throws NoSuchMethodException, SecurityException {
    Method method = SampleRepository.class.getMethod("findByTitleRegex", String.class);

    Query query = createQueryForMethodWithArgs(method, new Object[] {"(\\+ \\*)"});
    Assert.assertEquals("title:(\\+ \\*)", queryParser.getQueryString(query));
  }
コード例 #8
0
  @Test
  public void testCreateQueryWithArrayType() throws NoSuchMethodException, SecurityException {
    Method method = SampleRepository.class.getMethod("findByPopularityLike", String[].class);

    Query query =
        createQueryForMethodWithArgs(method, new Object[] {new String[] {"one", "two", "three"}});
    Assert.assertEquals("popularity:(one* two* three*)", queryParser.getQueryString(query));
  }
コード例 #9
0
  @Test
  public void testCreateQueryWithBetweenClause() throws NoSuchMethodException, SecurityException {
    Method method =
        SampleRepository.class.getMethod("findByPopularityBetween", Integer.class, Integer.class);

    Query query = createQueryForMethodWithArgs(method, new Object[] {100, 200});
    Assert.assertEquals("popularity:[100 TO 200]", queryParser.getQueryString(query));
  }
コード例 #10
0
  @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));
  }
コード例 #11
0
  @Test
  public void testCreateQueryWithContainingClauseUsingCollection()
      throws NoSuchMethodException, SecurityException {
    Method method = SampleRepository.class.getMethod("findByTitleContaining", Collection.class);

    Query query =
        createQueryForMethodWithArgs(method, new Object[] {Arrays.asList("one", "two", "three")});
    Assert.assertEquals("title:(*one* *two* *three*)", queryParser.getQueryString(query));
  }
コード例 #12
0
  @Test
  public void testCreateQueryWithAfterClause() throws NoSuchMethodException, SecurityException {
    Method method = SampleRepository.class.getMethod("findByLastModifiedAfter", Date.class);

    Query query =
        createQueryForMethodWithArgs(
            method, new Object[] {new DateTime(2012, 10, 15, 5, 31, 0, DateTimeZone.UTC)});
    Assert.assertEquals(
        "last_modified:{2012\\-10\\-15T05\\:31\\:00.000Z TO *]", queryParser.getQueryString(query));
  }
コード例 #13
0
  @Test
  public void testCreateQueryWithWithin() throws NoSuchMethodException, SecurityException {
    Method method =
        SampleRepository.class.getMethod("findByLocationWithin", Point.class, Distance.class);

    Query query =
        createQueryForMethodWithArgs(
            method, new Object[] {new Point(48.303056, 14.290556), new Distance(5)});
    Assert.assertEquals(
        "{!geofilt pt=48.303056,14.290556 sfield=store d=5.0}", queryParser.getQueryString(query));
  }
コード例 #14
0
  @Test
  public void testCreateQueryWithNearWhereUnitIsMiles()
      throws NoSuchMethodException, SecurityException {
    Method method =
        SampleRepository.class.getMethod("findByLocationNear", Point.class, Distance.class);

    Query query =
        createQueryForMethodWithArgs(
            method, new Object[] {new Point(48.303056, 14.290556), new Distance(1, Metrics.MILES)});
    Assert.assertEquals(
        "{!bbox pt=48.303056,14.290556 sfield=store d=1.609344}",
        queryParser.getQueryString(query));
  }
コード例 #15
0
  @Test
  public void testQueryCreationSingleProperty() throws NoSuchMethodException, SecurityException {
    Method method = SampleRepository.class.getMethod("findByText", String.class);
    SolrQueryMethod queryMethod =
        new SolrQueryMethod(method, metadataMock, entityInformationCreatorMock);

    StringBasedSolrQuery solrQuery = new StringBasedSolrQuery(queryMethod, solrOperationsMock);

    org.springframework.data.solr.core.query.Query query =
        solrQuery.createQuery(
            new SolrParametersParameterAccessor(queryMethod, new Object[] {"j73x73r"}));

    Assert.assertEquals("textGeneral:j73x73r", queryParser.getQueryString(query));
  }
コード例 #16
0
  @Test
  public void testCreateQueryWithNearUsingBoundingBox()
      throws NoSuchMethodException, SecurityException {
    Method method = SampleRepository.class.getMethod("findByLocationNear", Box.class);

    Query query =
        createQueryForMethodWithArgs(
            method,
            new Object[] {
              new Box(new Point(48.303056, 14.290556), new Point(48.306377, 14.283128))
            });
    Assert.assertEquals(
        "store:[48.303056,14.290556 TO 48.306377,14.283128]", queryParser.getQueryString(query));
  }
コード例 #17
0
  @Test
  public void testQueryCreationMultiyProperty() throws NoSuchMethodException, SecurityException {
    Method method =
        SampleRepository.class.getMethod("findByPopularityAndPrice", Integer.class, Float.class);
    SolrQueryMethod queryMethod =
        new SolrQueryMethod(method, metadataMock, entityInformationCreatorMock);

    StringBasedSolrQuery solrQuery = new StringBasedSolrQuery(queryMethod, solrOperationsMock);

    org.springframework.data.solr.core.query.Query query =
        solrQuery.createQuery(
            new SolrParametersParameterAccessor(
                queryMethod, new Object[] {Integer.valueOf(1), Float.valueOf(2f)}));

    Assert.assertEquals("popularity:1 AND price:2.0", queryParser.getQueryString(query));
  }
コード例 #18
0
  @Test
  public void testWithPointProperty() throws NoSuchMethodException, SecurityException {
    Method method =
        SampleRepository.class.getMethod("findByLocationNear", Point.class, Distance.class);
    SolrQueryMethod queryMethod =
        new SolrQueryMethod(method, metadataMock, entityInformationCreatorMock);

    StringBasedSolrQuery solrQuery = new StringBasedSolrQuery(queryMethod, solrOperationsMock);

    org.springframework.data.solr.core.query.Query query =
        solrQuery.createQuery(
            new SolrParametersParameterAccessor(
                queryMethod, new Object[] {new Point(48.303056, 14.290556), new Distance(5)}));

    Assert.assertEquals(
        "{!geofilt pt=48.303056,14.290556 sfield=store d=5.0}", queryParser.getQueryString(query));
  }
コード例 #19
0
  @Test
  public void testWithSort() throws NoSuchMethodException, SecurityException {
    Method method =
        SampleRepository.class.getMethod("findByNameWithSort", String.class, Sort.class);
    SolrQueryMethod queryMethod =
        new SolrQueryMethod(method, metadataMock, entityInformationCreatorMock);

    StringBasedSolrQuery solrQuery = new StringBasedSolrQuery(queryMethod, solrOperationsMock);
    Sort sort = new Sort(Direction.DESC, "popularity", "price");

    org.springframework.data.solr.core.query.Query query =
        solrQuery.createQuery(
            new SolrParametersParameterAccessor(queryMethod, new Object[] {"spring", sort}));

    Assert.assertEquals("name:spring", queryParser.getQueryString(query));
    Assert.assertEquals(sort, query.getSort());
  }
コード例 #20
0
  @Test
  public void testWithProjectionOnSingleField() throws NoSuchMethodException, SecurityException {
    Method method =
        SampleRepository.class.getMethod("findByNameProjectionOnPopularity", String.class);
    SolrQueryMethod queryMethod =
        new SolrQueryMethod(method, metadataMock, entityInformationCreatorMock);

    StringBasedSolrQuery solrQuery = new StringBasedSolrQuery(queryMethod, solrOperationsMock);

    org.springframework.data.solr.core.query.Query query =
        solrQuery.createQuery(
            new SolrParametersParameterAccessor(queryMethod, new Object[] {"christoph"}));

    Assert.assertEquals("name:christoph*", queryParser.getQueryString(query));
    Assert.assertEquals(1, query.getProjectionOnFields().size());
    Assert.assertEquals("popularity", query.getProjectionOnFields().get(0).getName());
  }
コード例 #21
0
  /** @see DATASOLR-139 */
  @Test
  public void testCombinationsOfOrAndShouldBeCreatedCorrectly()
      throws NoSuchMethodException, SecurityException {

    Method method =
        SampleRepository.class.getMethod(
            "findByNameOrDescriptionAndLastModifiedAfter", String.class, String.class, Date.class);

    Query query =
        createQueryForMethodWithArgs(
            method,
            new Object[] {
              "mail", "domain", new DateTime(2012, 10, 15, 5, 31, 0, DateTimeZone.UTC)
            });
    Assert.assertEquals(
        "name:mail OR description:domain AND last_modified:{2012\\-10\\-15T05\\:31\\:00.000Z TO *]",
        queryParser.getQueryString(query));
  }