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

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


    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"));
    groupOptions.addGroupByField("name");
    groupOptions.addGroupByFunction(f);
    groupOptions.addGroupByQuery(q1);
    groupOptions.addGroupByQuery(q2);
View Full Code Here


    solrTemplate.commit();

    StatsOptions statsOptions = new StatsOptions().addField("popularity").addField("price")
        .setSelectiveCalcDistinct(true);

    SimpleQuery statsQuery = new SimpleQuery(new SimpleStringCriteria("*:*"));
    statsQuery.setStatsOptions(statsOptions);
    StatsPage<ExampleSolrBean> statResultPage = solrTemplate.queryForStatsPage(statsQuery, ExampleSolrBean.class);

    FieldStatsResult priceStatResult = statResultPage.getFieldStatsResult("price");
    FieldStatsResult popularityStatResult = statResultPage.getFieldStatsResult("popularity");

View Full Code Here

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

    SimpleQuery statsQuery = new SimpleQuery(new SimpleStringCriteria("*:*"));
    statsQuery.setStatsOptions(statsOptions);
    StatsPage<ExampleSolrBean> statResultPage = solrTemplate.queryForStatsPage(statsQuery, ExampleSolrBean.class);

    FieldStatsResult priceStats = statResultPage.getFieldStatsResult("price");
    Assert.assertEquals(Long.valueOf(2), priceStats.getCount());
    Assert.assertEquals(10D, priceStats.getMin());
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);

    long result = solrTemplate.count(new SimpleQuery(new Criteria("field_1").is("value1")));
    Assert.assertEquals(resultList.getNumFound(), result);

    Mockito.verify(solrServerMock, Mockito.times(1)).query(captor.capture());

    Assert.assertEquals(Integer.valueOf(0), captor.getValue().getStart());
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

      }

    };

    solrTemplate.registerQueryParser(SimpleQuery.class, parser);
    solrTemplate.query(new SimpleQuery(new SimpleStringCriteria("my:criteria")));

    ArgumentCaptor<SolrParams> captor = ArgumentCaptor.forClass(SolrParams.class);

    Mockito.verify(solrServerMock, Mockito.times(1)).query(captor.capture());
    Assert.assertEquals("*:*", captor.getValue().getParams(CommonParams.Q)[0]);
View Full Code Here

    Assert.assertEquals("field_1:001", queryParser.createQueryStringFromCriteria(criteria));
  }

  @Test
  public void testConstructSimpleSolrQuery() {
    Query query = new SimpleQuery(new Criteria("field_1").is("value_1"));
    SolrQuery solrQuery = queryParser.constructSolrQuery(query);
    Assert.assertNotNull(solrQuery);
    assertQueryStringPresent(solrQuery);
    assertPaginationNotPresent(solrQuery);
    assertProjectionNotPresent(solrQuery);
View Full Code Here

  @Test
  public void testConstructSolrQueryWithPagination() {
    int page = 1;
    int pageSize = 100;
    Query query = new SimpleQuery(new Criteria("field_1").is("value_1"))
        .setPageRequest(new PageRequest(page, pageSize));
    SolrQuery solrQuery = queryParser.constructSolrQuery(query);
    Assert.assertNotNull(solrQuery);
    assertQueryStringPresent(solrQuery);
    assertPaginationPresent(solrQuery, page * pageSize, pageSize);
View Full Code Here

    assertFactingNotPresent(solrQuery);
  }

  @Test
  public void testConstructSimpleSolrQueryWithProjection() {
    Query query = new SimpleQuery(new Criteria("field_1").is("value_1")).addProjectionOnField("projection_1")
        .addProjectionOnField(new SimpleField("projection_2"));
    SolrQuery solrQuery = queryParser.constructSolrQuery(query);
    Assert.assertNotNull(solrQuery);
    assertQueryStringPresent(solrQuery);
    assertPaginationNotPresent(solrQuery);
View Full Code Here

    assertFactingNotPresent(solrQuery);
  }

  @Test
  public void testConstructSolrQueryWithSingleGroupBy() {
    Query query = new SimpleQuery(new Criteria("field_1").is("value_1")).addGroupByField("group_1");
    SolrQuery solrQuery = queryParser.constructSolrQuery(query);
    Assert.assertNotNull(solrQuery);
    assertQueryStringPresent(solrQuery);
    assertPaginationNotPresent(solrQuery);
    assertProjectionNotPresent(solrQuery);
View Full Code Here

TOP

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

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.