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

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


  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));
  }
 
View Full Code Here


  @Test
  public void testNamedObjectsGroupQuery() {
    List<Function> functionList = Arrays.asList(Mockito.mock(Function.class), Mockito.mock(Function.class));
    List<Query> queriesList = Arrays.asList(Mockito.mock(Query.class), Mockito.mock(Query.class));

    Query groupQueryMock = Mockito.mock(Query.class);
    GroupOptions groupOptions = Mockito.mock(GroupOptions.class);
    Mockito.when(groupQueryMock.getGroupOptions()).thenReturn(groupOptions);
    Mockito.when(groupOptions.getGroupByFunctions()).thenReturn(functionList);
    Mockito.when(groupOptions.getGroupByQueries()).thenReturn(queriesList);

    NamedObjectsQuery decorator = new NamedObjectsQuery(groupQueryMock);
    decorator.setName(functionList.get(0), "nameFunc0");
View Full Code Here

    SolrDocumentList resultList = new SolrDocumentList();
    resultList.setNumFound(10);
    Mockito.when(responseMock.getResults()).thenReturn(resultList);
    Mockito.when(solrServerMock.query(Mockito.any(SolrQuery.class))).thenReturn(responseMock);

    Query query = new SimpleQuery(new Criteria("field_1").is("value1"));
    query.setPageRequest(new PageRequest(0, 5));
    long result = solrTemplate.count(query);
    Assert.assertEquals(resultList.getNumFound(), result);

    Mockito.verify(solrServerMock, Mockito.times(1)).query(captor.capture());
View Full Code Here

      values.add(createExampleBeanWithId(Integer.toString(i)));
    }
    solrTemplate.saveBeans(values);
    solrTemplate.commit();

    Query query = new SimpleQuery(new SimpleStringCriteria("*:*")).addSort(new Sort(Sort.Direction.DESC, "name"));
    Page<ExampleSolrBean> page = solrTemplate.queryForPage(query, ExampleSolrBean.class);

    ExampleSolrBean prev = page.getContent().get(0);
    for (int i = 1; i < page.getContent().size(); i++) {
      ExampleSolrBean cur = page.getContent().get(i);
View Full Code Here

      values.add(bean);
    }
    solrTemplate.saveBeans(values);
    solrTemplate.commit();

    Query query = new SimpleQuery(new SimpleStringCriteria("*:*")).addSort(new Sort(Sort.Direction.DESC, "inStock"))
        .addSort(new Sort(Sort.Direction.ASC, "name"));
    Page<ExampleSolrBean> page = solrTemplate.queryForPage(query, ExampleSolrBean.class);

    ExampleSolrBean prev = page.getContent().get(0);
    for (int i = 1; i < 5; i++) {
View Full Code Here

    ExampleSolrBean bean1 = new ExampleSolrBean("id-1", "one", null);
    ExampleSolrBean bean2 = new ExampleSolrBean("id-2", "two", null);
    solrTemplate.saveBeans(Arrays.asList(bean1, bean2));
    solrTemplate.commit();

    Query q = new SimpleQuery("*:*").addFilterQuery(new SimpleFilterQuery(new Criteria(QueryFunction
        .query("{!query v = 'one'}"))));

    Page<ExampleSolrBean> result = solrTemplate.queryForPage(q, ExampleSolrBean.class);
    Assert.assertThat(result.getContent().get(0).getId(), IsEqual.equalTo(bean1.getId()));
  }
View Full Code Here

    ExampleSolrBean bean1 = new ExampleSolrBean("id-1", "one", null);
    ExampleSolrBean bean2 = new ExampleSolrBean("id-2", "two", null);
    solrTemplate.saveBeans(Arrays.asList(bean1, bean2));
    solrTemplate.commit();

    Query q = new SimpleQuery(new Criteria(QueryFunction.query("{!query v='two'}")));

    Page<ExampleSolrBean> result = solrTemplate.queryForPage(q, ExampleSolrBean.class);
    Assert.assertThat(result.getContent().get(0).getId(), Is.is(bean2.getId()));
  }
View Full Code Here

    bean2.setStore("40.7143,-74.006");

    solrTemplate.saveBeans(Arrays.asList(bean1, bean2));
    solrTemplate.commit();

    Query q = new SimpleQuery("*:*");
    q.addProjectionOnField(new DistanceField("distance", "store", new Point(45.15, -93.85)));
    Page<ExampleSolrBean> result = solrTemplate.queryForPage(q, ExampleSolrBean.class);
    for (ExampleSolrBean bean : result) {
      Assert.assertThat(bean.getDistance(), IsNull.notNullValue());
    }

View Full Code Here

    solrTemplate.saveBean(new ExampleSolrBean("id_3", "name2", "category2", 1, true));
    solrTemplate.saveBean(new ExampleSolrBean("id_4", "name3", "category2"));
    solrTemplate.commit();

    Function f = IfFunction.when("inStock").then("1").otherwise("2");
    Query q1 = new SimpleQuery("cat:category2");
    Query q2 = new SimpleQuery("cat:category1");

    SimpleQuery groupQuery = new SimpleQuery(new SimpleStringCriteria("*:*"));
    GroupOptions groupOptions = new GroupOptions();
    groupQuery.setGroupOptions(groupOptions);
    groupOptions.addSort(new Sort("name", "id"));
View Full Code Here

  @Test
  public void testGetGroupResultQuery() {
    @SuppressWarnings("unchecked")
    GroupResult<Object> gr = new SimpleGroupResult<Object>(1, null, "name", Mockito.mock(Page.class));

    Query query = Mockito.mock(Query.class);

    Map<Object, GroupResult<Object>> groupResultMap = new HashMap<Object, GroupResult<Object>>();
    groupResultMap.put(query, gr);

    SolrResultPage<Object> result = new SolrResultPage<Object>(Collections.emptyList());
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.