List of usage examples for org.apache.solr.common SolrDocumentList SolrDocumentList
SolrDocumentList
From source file:org.pentaho.di.trans.steps.solrinput.SolrInputData.java
License:Apache License
public SolrInputData() { super();//from w w w .j av a 2s . c o m recordIndex = 0; facetCountName = ""; facetRequested = false; documentList = new SolrDocumentList(); facetCounts = new ArrayList<FacetField.Count>(); }
From source file:org.phenotips.vocabulary.internal.solr.HumanPhenotypeOntologyTest.java
License:Open Source License
@Test public void testHumanPhenotypeOntologySuggestTermsIsId() throws ComponentLookupException, SolrServerException, IOException { QueryResponse response = mock(QueryResponse.class); when(this.server.query(any(SolrParams.class))).thenReturn(response); when(response.getSpellCheckResponse()).thenReturn(null); when(response.getResults()).thenReturn(new SolrDocumentList()); this.mocker.getComponentUnderTest().search("HP:0001", 0, null, null); verify(this.server).query(argThat(new IsIdQuery())); }
From source file:org.phenotips.vocabulary.internal.solr.HumanPhenotypeOntologyTest.java
License:Open Source License
@Test public void testHumanPhenotypeOntologySuggestTermsIsNotId() throws ComponentLookupException, SolrServerException, IOException { QueryResponse response = mock(QueryResponse.class); when(this.server.query(any(SolrParams.class))).thenReturn(response); when(response.getSpellCheckResponse()).thenReturn(null); when(response.getResults()).thenReturn(new SolrDocumentList()); this.mocker.getComponentUnderTest().search("HP:Test", 0, null, null); verify(this.server).query(argThat(new IsDisMaxQuery())); }
From source file:org.phenotips.vocabulary.internal.solr.HumanPhenotypeOntologyTest.java
License:Open Source License
@Test public void testHumanPhenotypeOntologySuggestTermsMultipleWords() throws ComponentLookupException, SolrServerException, IOException { QueryResponse response = mock(QueryResponse.class); when(this.server.query(any(SolrParams.class))).thenReturn(response); when(response.getSpellCheckResponse()).thenReturn(null); when(response.getResults()).thenReturn(new SolrDocumentList()); this.mocker.getComponentUnderTest().search("first second", 0, null, null); verify(this.server).query(argThat(new IsDisMaxQuery())); }
From source file:org.sakaiproject.nakamura.search.solr.SolrSearchResultSetImpl.java
License:Apache License
private void loadResponse() { if (responseList == null) { // null list so let's try to load it NamedList<Object> response = queryResponse.getResponse(); responseList = new SolrDocumentList(); if (response.get("moreLikeThis") != null) { // The moreLikeThis response will contain a regular result set, but it's // the extra stuff we're interested in. loadMoreLikeThisResponse(response); } else {/*from w ww. j av a 2s . c o m*/ responseList = queryResponse.getResults(); if (responseList == null) { // will be null if search was grouped responseList = new SolrDocumentList(); // Must be one of our alternative query types. if (response.get("grouped") != null) { loadGroupedResponse(response); } } } } }
From source file:org.springframework.data.solr.core.convert.MappingSolrConvertDocumentObjectBinderCompatibilityTests.java
License:Apache License
@Test public void testToAndFromSolrDocument() { Item item = new Item(); item.id = "one"; item.inStock = false;/*from w w w .j ava 2s. com*/ item.categories = new String[] { "aaa", "bbb", "ccc" }; item.features = Arrays.asList(item.categories); List<String> supA = Arrays.asList("supA1", "supA2", "supA3"); List<String> supB = Arrays.asList("supB1", "supB2", "supB3"); item.supplier = new HashMap<String, List<String>>(); item.supplier.put("supplier_supA", supA); item.supplier.put("supplier_supB", supB); item.supplier_simple = new HashMap<String, String>(); item.supplier_simple.put("sup_simple_supA", "supA_val"); item.supplier_simple.put("sup_simple_supB", "supB_val"); SolrInputDocument doc = new SolrInputDocument(); converter.write(item, doc); SolrDocumentList docs = new SolrDocumentList(); docs.add(ClientUtils.toSolrDocument(doc)); Item out = converter.read(Item.class, docs.get(0)); // make sure it came out the same Assert.assertEquals(item.id, out.id); Assert.assertEquals(item.inStock, out.inStock); Assert.assertEquals(item.categories.length, out.categories.length); Assert.assertEquals(item.features, out.features); Assert.assertEquals(supA, out.supplier.get("supplier_supA")); Assert.assertEquals(supB, out.supplier.get("supplier_supB")); Assert.assertEquals(item.supplier_simple.get("sup_simple_supB"), out.supplier_simple.get("sup_simple_supB")); // put back "out" as Bean, to see if both ways work as you would expect // but the Field that "allSuppliers" need to be cleared, as it is just for // retrieving data, not to post data out.allSuppliers = null; SolrInputDocument doc1 = new SolrInputDocument(); converter.write(out, doc1); SolrDocumentList docs1 = new SolrDocumentList(); docs1.add(ClientUtils.toSolrDocument(doc1)); Item out1 = converter.read(Item.class, docs1.get(0)); Assert.assertEquals(item.id, out1.id); Assert.assertEquals(item.inStock, out1.inStock); Assert.assertEquals(item.categories.length, out1.categories.length); Assert.assertEquals(item.features, out1.features); Assert.assertEquals(item.supplier_simple.get("sup_simple_supB"), out1.supplier_simple.get("sup_simple_supB")); Assert.assertEquals(supA, out1.supplier.get("supplier_supA")); Assert.assertEquals(supB, out1.supplier.get("supplier_supB")); }
From source file:org.springframework.data.solr.core.SolrTemplateMulticoreTests.java
License:Apache License
@Test public void testCountQueries() throws SolrServerException, IOException { ArgumentCaptor<SolrQuery> captor1 = ArgumentCaptor.forClass(SolrQuery.class); ArgumentCaptor<SolrQuery> captor2 = ArgumentCaptor.forClass(SolrQuery.class); QueryResponse response1Mock = Mockito.mock(QueryResponse.class); SolrDocumentList resultList1 = new SolrDocumentList(); resultList1.setNumFound(10);//from w ww . j av a2 s .co m Mockito.when(response1Mock.getResults()).thenReturn(resultList1); QueryResponse response2Mock = Mockito.mock(QueryResponse.class); SolrDocumentList resultList2 = new SolrDocumentList(); resultList2.setNumFound(10); Mockito.when(response2Mock.getResults()).thenReturn(resultList2); Mockito.when(core1Client.query(Mockito.any(SolrQuery.class), Mockito.eq(SolrRequest.METHOD.GET))) .thenReturn(response1Mock); Mockito.when(core2Client.query(Mockito.any(SolrQuery.class), Mockito.eq(SolrRequest.METHOD.GET))) .thenReturn(response2Mock); long result1 = solrTemplate.count("core1", new SimpleQuery(new Criteria("field_1").is("value1"))); long result2 = solrTemplate.count("core2", new SimpleQuery(new Criteria("field_2").is("value2"))); assertEquals(resultList1.getNumFound(), result1); assertEquals(resultList2.getNumFound(), result2); Mockito.verify(core1Client, Mockito.times(1)).query(captor1.capture(), Mockito.eq(SolrRequest.METHOD.GET)); Mockito.verify(core2Client, Mockito.times(1)).query(captor2.capture(), Mockito.eq(SolrRequest.METHOD.GET)); }
From source file:org.springframework.data.solr.core.SolrTemplateTest.java
License:Apache License
@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 va 2 s. co 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
License:Apache License
@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);//from w w w. j a v a 2 s . com 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()); }
From source file:org.springframework.data.solr.core.SolrTemplateTests.java
License:Apache License
/** * @see DATASOLR-83//from ww w . j a v a2 s . c o m */ @Test public void testGetById() throws SolrServerException, IOException { ArgumentCaptor<SolrRequest> captor = ArgumentCaptor.forClass(SolrRequest.class); QueryResponse responseMock = Mockito.mock(QueryResponse.class); SolrDocumentList resultList = new SolrDocumentList(); Mockito.when(responseMock.getResults()).thenReturn(resultList); Mockito.when(solrServerMock.request(captor.capture())).thenReturn(new NamedList<Object>()); DocumentWithIndexAnnotations result = solrTemplate.getById("myId", DocumentWithIndexAnnotations.class); Mockito.verify(solrServerMock, Mockito.times(1)).request(captor.capture()); Assert.assertNull(result); Assert.assertEquals("myId", captor.getValue().getParams().get("ids")); Assert.assertEquals("/get", captor.getValue().getPath()); }