Example usage for org.springframework.data.solr.core.query SimpleQuery SimpleQuery

List of usage examples for org.springframework.data.solr.core.query SimpleQuery SimpleQuery

Introduction

In this page you can find the example usage for org.springframework.data.solr.core.query SimpleQuery SimpleQuery.

Prototype

public SimpleQuery(String queryString) 

Source Link

Usage

From source file:org.springframework.data.solr.core.QueryParserTest.java

@Test
public void testWithSortMixedDirections() {
    SimpleStringCriteria criteria = new SimpleStringCriteria("field_1:value_1");
    Query query = new SimpleQuery(criteria);
    query.addSort(new Sort("field_1"));
    query.addSort(new Sort(Sort.Direction.DESC, "field_2, field_3"));
    SolrQuery solrQuery = queryParser.constructSolrQuery(query);
    Assert.assertEquals("field_1 asc,field_2, field_3 desc", solrQuery.getSortField());
    Assert.assertEquals(3, solrQuery.getSortFields().length);
}

From source file:org.springframework.data.solr.core.SolrTemplateTest.java

@Test
public void testCount() throws SolrServerException {
    ArgumentCaptor<SolrQuery> captor = ArgumentCaptor.forClass(SolrQuery.class);
    QueryResponse responseMock = Mockito.mock(QueryResponse.class);
    SolrDocumentList resultList = new SolrDocumentList();
    resultList.setNumFound(10);//w  w w . j a v  a 2s .  c  o m
    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());
    Assert.assertEquals(Integer.valueOf(0), captor.getValue().getRows());
}

From source file:org.springframework.data.solr.core.SolrTemplateTest.java

@Test
public void testCountWhenPagingSet() throws SolrServerException {
    ArgumentCaptor<SolrQuery> captor = ArgumentCaptor.forClass(SolrQuery.class);
    QueryResponse responseMock = Mockito.mock(QueryResponse.class);
    SolrDocumentList resultList = new SolrDocumentList();
    resultList.setNumFound(10);// ww  w .  j  a va 2s .co m
    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());

    Assert.assertEquals(Integer.valueOf(0), captor.getValue().getStart());
    Assert.assertEquals(Integer.valueOf(0), captor.getValue().getRows());
}