Java Code Examples for org.apache.solr.common.SolrDocumentList#add()
The following examples show how to use
org.apache.solr.common.SolrDocumentList#add() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractSolrSentryTestBase.java From incubator-sentry with Apache License 2.0 | 6 votes |
/** * Method to validate Solr update passes * @param solrUserName - User authenticated into Solr * @param collectionName - Name of the collection to which the data has to be updated * @param solrInputDoc - Instance of SolrInputDocument * @throws Exception */ protected void verifyUpdatePass(String solrUserName, String collectionName, SolrInputDocument solrInputDoc) throws Exception { String originalUser = getAuthenticatedUser(); try { SolrDocumentList orginalSolrDocs = getSolrDocs(collectionName, ALL_DOCS, true); setAuthenticationUser(solrUserName); CloudSolrServer cloudSolrServer = getCloudSolrServer(collectionName); try { cloudSolrServer.add(solrInputDoc); cloudSolrServer.commit(); } finally { cloudSolrServer.shutdown(); } orginalSolrDocs.add(ClientUtils.toSolrDocument(solrInputDoc)); SolrDocumentList solrRespDocs = getSolrDocs(collectionName, ALL_DOCS, true); // Validate Solr content to check whether the update command went through. validateSolrDocCountAndContent(orginalSolrDocs, solrRespDocs); } finally { setAuthenticationUser(originalUser); } }
Example 2
Source File: SolrClientInterceptorTest.java From skywalking with Apache License 2.0 | 6 votes |
private NamedList<Object> getGetResponse() { NamedList<Object> response = new NamedList<Object>(); response.add("responseHeader", header); SolrDocumentList list = new SolrDocumentList(); list.setStart(0); list.setNumFound(1); list.setMaxScore(.0f); SolrDocument doc = new SolrDocument(); doc.addField("id", 1); doc.addField("_version", 1634676349644832768L); list.add(doc); response.add("response", list); return response; }
Example 3
Source File: MockSolrEntityProcessor.java From lucene-solr with Apache License 2.0 | 6 votes |
private SolrDocumentList getDocs(int start, int rows) { SolrDocumentList docs = new SolrDocumentList(); docs.setNumFound(docsData.size()); docs.setStart(start); int endIndex = start + rows; int end = docsData.size() < endIndex ? docsData.size() : endIndex; for (int i = start; i < end; i++) { SolrDocument doc = new SolrDocument(); SolrTestCaseJ4.Doc testDoc = docsData.get(i); doc.addField("id", testDoc.id); doc.addField("description", testDoc.getValues("description")); docs.add(doc); } return docs; }
Example 4
Source File: LogWatcher.java From lucene-solr with Apache License 2.0 | 6 votes |
public SolrDocumentList getHistory(long since, AtomicBoolean found) { if(history==null) { return null; } SolrDocumentList docs = new SolrDocumentList(); Iterator<E> iter = history.iterator(); while(iter.hasNext()) { E e = iter.next(); long ts = getTimestamp(e); if(ts == since) { if(found!=null) { found.set(true); } } if(ts>since) { docs.add(toSolrDocument(e)); } } docs.setNumFound(docs.size()); // make it not look too funny return docs; }
Example 5
Source File: SolrClientInterceptorTest.java From skywalking with Apache License 2.0 | 6 votes |
private NamedList<Object> getQueryResponse() { NamedList<Object> response = new NamedList<Object>(); response.add("responseHeader", header); SolrDocumentList list = new SolrDocumentList(); list.setStart(0); list.setNumFound(100); list.setMaxScore(.0f); for (int start = 0; start < 10; start++) { SolrDocument doc = new SolrDocument(); doc.addField("id", start); doc.addField("_version", 1634676349644832768L); list.add(doc); } response.add("response", list); return response; }
Example 6
Source File: TestRandomFlRTGCloud.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * trivial helper method to deal with diff response structure between using a single 'id' param vs * 2 or more 'id' params (or 1 or more 'ids' params). * * @return List from response, or a synthetic one created from single response doc if * <code>expectList</code> was false; May be empty; May be null if response included null list. */ private static SolrDocumentList getDocsFromRTGResponse(final boolean expectList, final QueryResponse rsp) { if (expectList) { return rsp.getResults(); } // else: expect single doc, make our own list... final SolrDocumentList result = new SolrDocumentList(); NamedList<Object> raw = rsp.getResponse(); Object doc = raw.get("doc"); if (null != doc) { result.add((SolrDocument) doc); result.setNumFound(1); } return result; }
Example 7
Source File: SolrUtils.java From vind with Apache License 2.0 | 6 votes |
public static GetResult buildRealTimeGetResult(QueryResponse response, RealTimeGet query, DocumentFactory factory) { final String DOC = "doc"; long nResults = 0; List<Document> docResults = new ArrayList<>(); final SolrDocumentList results = response.getResults(); if(results != null && results.size() >0){ docResults = buildResultList(results, null, factory, null); nResults = docResults.size(); } else { final SolrDocument solrDoc = (SolrDocument)response.getResponse().get(DOC); if(solrDoc != null) { final SolrDocumentList solrDocuments = new SolrDocumentList(); solrDocuments.add(solrDoc); docResults = buildResultList(solrDocuments, null, factory, null); nResults = 1; } } return new GetResult(nResults,docResults,query,factory,response.getQTime()).setElapsedTime(response.getElapsedTime()); }
Example 8
Source File: SmileWriterTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@SuppressWarnings({"unchecked"}) public static SolrDocumentList constructSolrDocList(SolrQueryResponse response) { SolrDocumentList l = new SolrDocumentList(); for(int i=0;i<10; i++){ l.add(sampleDoc(random(), i)); } response.getValues().add("results", l); return l; }
Example 9
Source File: SolrSearchDaoTest.java From metron with Apache License 2.0 | 5 votes |
@Test public void getAllLatestShouldProperlyReturnDocuments() throws Exception { GetRequest broRequest1 = new GetRequest("bro-1", "bro"); GetRequest broRequest2 = new GetRequest("bro-2", "bro"); GetRequest snortRequest1 = new GetRequest("snort-1", "snort"); GetRequest snortRequest2 = new GetRequest("snort-2", "snort"); SolrDocument broSolrDoc1 = createSolrDocument("bro", 12345L); SolrDocument broSolrDoc2 = createSolrDocument("bro", 34567L); SolrDocument snortSolrDoc1 = createSolrDocument("snort", 12345L); SolrDocument snortSolrDoc2 = createSolrDocument("snort", 67890L); Document broDoc1 = SolrUtilities.toDocument(broSolrDoc1); Document broDoc2 = SolrUtilities.toDocument(broSolrDoc2); Document snortDoc1 = SolrUtilities.toDocument(snortSolrDoc1); Document snortDoc2 = SolrUtilities.toDocument(snortSolrDoc2); solrSearchDao = spy(new SolrSearchDao(client, accessConfig)); SolrDocumentList broList = new SolrDocumentList(); broList.add(broSolrDoc1); broList.add(broSolrDoc2); SolrDocumentList snortList = new SolrDocumentList(); snortList.add(snortSolrDoc1); snortList.add(snortSolrDoc2); when(client.getById((List<String>) org.mockito.hamcrest.MockitoHamcrest.argThat(hasItems("bro-1", "bro-2")), argThat( new ModifiableSolrParamsMatcher(new ModifiableSolrParams().set("collection", "bro"))))) .thenReturn(broList); when(client.getById((List<String>) org.mockito.hamcrest.MockitoHamcrest.argThat(hasItems("snort-1", "snort-2")), argThat(new ModifiableSolrParamsMatcher( new ModifiableSolrParams().set("collection", "snort"))))).thenReturn(snortList); assertEquals(Arrays.asList(broDoc1, broDoc2, snortDoc1, snortDoc2), solrRetrieveLatestDao .getAllLatest(Arrays.asList(broRequest1, broRequest2, snortRequest1, snortRequest2))); }
Example 10
Source File: TestCloudInspectUtil.java From lucene-solr with Apache License 2.0 | 5 votes |
private SolrDocumentList getDocList(String ... ids) { SolrDocumentList list = new SolrDocumentList(); for (String id : ids) { SolrDocument doc = new SolrDocument(); doc.addField("id", id); list.add(doc); } return list; }
Example 11
Source File: GroupedEndResultTransformer.java From lucene-solr with Apache License 2.0 | 5 votes |
private static void retrieveAndAdd(SolrDocumentList solrDocumentList, SolrDocumentSource solrDocumentSource, ScoreDoc[] scoreDocs) { for (ScoreDoc scoreDoc : scoreDocs) { SolrDocument solrDocument = solrDocumentSource.retrieve(scoreDoc); if (solrDocument != null) { solrDocumentList.add(solrDocument); } } }
Example 12
Source File: TestDocumentObjectBinder.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testSingleVal4Array() { DocumentObjectBinder binder = new DocumentObjectBinder(); SolrDocumentList solDocList = new SolrDocumentList(); SolrDocument d = new SolrDocument(); solDocList.add(d); d.setField("cat", "hello"); List<Item> l = binder.getBeans(Item.class, solDocList); assertEquals("hello", l.get(0).categories[0]); }
Example 13
Source File: XMLResponseParser.java From lucene-solr with Apache License 2.0 | 5 votes |
protected SolrDocumentList readDocuments( XMLStreamReader parser ) throws XMLStreamException { SolrDocumentList docs = new SolrDocumentList(); // Parse the attributes for( int i=0; i<parser.getAttributeCount(); i++ ) { String n = parser.getAttributeLocalName( i ); String v = parser.getAttributeValue( i ); if( "numFound".equals( n ) ) { docs.setNumFound( Long.parseLong( v ) ); } else if( "start".equals( n ) ) { docs.setStart( Long.parseLong( v ) ); } else if( "maxScore".equals( n ) ) { docs.setMaxScore( Float.parseFloat( v ) ); } } // Read through each document int event; while( true ) { event = parser.next(); if( XMLStreamConstants.START_ELEMENT == event ) { if( !"doc".equals( parser.getLocalName() ) ) { throw new RuntimeException( "should be doc! "+parser.getLocalName() + " :: " + parser.getLocation() ); } docs.add( readDocument( parser ) ); } else if ( XMLStreamConstants.END_ELEMENT == event ) { return docs; // only happens once } } }
Example 14
Source File: JSONWriterTest.java From lucene-solr with Apache License 2.0 | 4 votes |
@Test public void testJSONSolrDocument() throws Exception { SolrQueryRequest req = req(CommonParams.WT,"json", CommonParams.FL,"id,score,_children_,path"); SolrQueryResponse rsp = new SolrQueryResponse(); JSONResponseWriter w = new JSONResponseWriter(); ReturnFields returnFields = new SolrReturnFields(req); rsp.setReturnFields(returnFields); StringWriter buf = new StringWriter(); SolrDocument childDoc = new SolrDocument(); childDoc.addField("id", "2"); childDoc.addField("score", "0.4"); childDoc.addField("path", Arrays.asList("a>b", "a>b>c")); SolrDocumentList childList = new SolrDocumentList(); childList.setNumFound(1); childList.setStart(0); childList.add(childDoc); SolrDocument solrDoc = new SolrDocument(); solrDoc.addField("id", "1"); solrDoc.addField("subject", "hello2"); solrDoc.addField("title", "hello3"); solrDoc.addField("score", "0.7"); solrDoc.setField("_children_", childList); SolrDocumentList list = new SolrDocumentList(); list.setNumFound(1); list.setStart(0); list.setMaxScore(0.7f); list.add(solrDoc); rsp.addResponse(list); w.write(buf, req, rsp); String result = buf.toString(); assertFalse("response contains unexpected fields: " + result, result.contains("hello") || result.contains("\"subject\"") || result.contains("\"title\"")); assertTrue("response doesn't contain expected fields: " + result, result.contains("\"id\"") && result.contains("\"score\"") && result.contains("_children_")); String expectedResult = "{'response':{'numFound':1,'start':0,'maxScore':0.7, 'numFoundExact':true,'docs':[{'id':'1', 'score':'0.7'," + " '_children_':{'numFound':1,'start':0,'numFoundExact':true,'docs':[{'id':'2', 'score':'0.4', 'path':['a>b', 'a>b>c']}] }}] }}"; String error = JSONTestUtil.match(result, "=="+expectedResult); assertNull("response validation failed with error: " + error, error); req.close(); }
Example 15
Source File: TestJavaBinCodec.java From lucene-solr with Apache License 2.0 | 4 votes |
@SuppressWarnings({"unchecked"}) private List<Object> generateAllDataTypes() { List<Object> types = new ArrayList<>(); types.add(null); //NULL types.add(true); types.add(false); types.add((byte) 1); types.add((short) 2); types.add((double) 3); types.add(-4); types.add(4); types.add(42); types.add((long) -5); types.add((long) 5); types.add((long) 50); types.add((float) 6); types.add(new Date(0)); Map<Integer, Integer> map = new HashMap<>(); map.put(1, 2); types.add(map); SolrDocument doc = new SolrDocument(); doc.addField("foo", "bar"); types.add(doc); SolrDocumentList solrDocs = new SolrDocumentList(); solrDocs.setMaxScore(1.0f); solrDocs.setNumFound(1); solrDocs.setNumFoundExact(Boolean.TRUE); solrDocs.setStart(0); solrDocs.add(0, doc); types.add(solrDocs); types.add(new byte[] {1,2,3,4,5}); // TODO? // List<String> list = new ArrayList<String>(); // list.add("one"); // types.add(list.iterator()); types.add((byte) 15); //END SolrInputDocument idoc = new SolrInputDocument(); idoc.addField("foo", "bar"); types.add(idoc); SolrInputDocument parentDoc = new SolrInputDocument(); parentDoc.addField("foo", "bar"); SolrInputDocument childDoc = new SolrInputDocument(); childDoc.addField("foo", "bar"); parentDoc.addChildDocument(childDoc); types.add(parentDoc); types.add(new EnumFieldValue(1, "foo")); types.add(map.entrySet().iterator().next()); //Map.Entry types.add((byte) (1 << 5)); //TAG_AND_LEN types.add("foo"); types.add(1); types.add((long) 2); @SuppressWarnings({"rawtypes"}) SimpleOrderedMap simpleOrderedMap = new SimpleOrderedMap(); simpleOrderedMap.add("bar", "barbar"); types.add(simpleOrderedMap); NamedList<String> nl = new NamedList<>(); nl.add("foo", "barbar"); types.add(nl); return types; }
Example 16
Source File: SolrSearchDaoTest.java From metron with Apache License 2.0 | 4 votes |
@Test public void buildSearchResponseShouldReturnSearchResponse() { SearchRequest searchRequest = new SearchRequest(); searchRequest.setFields(Collections.singletonList("id")); searchRequest.setFacetFields(Collections.singletonList("facetField")); QueryResponse queryResponse = mock(QueryResponse.class); SolrDocument solrDocument1 = new SolrDocument(); solrDocument1.setField(Constants.GUID, "id1"); solrDocument1.setField("id", "id1"); SolrDocument solrDocument2 = new SolrDocument(); solrDocument2.setField(Constants.GUID, "id2"); solrDocument2.setField("id", "id2"); solrSearchDao = spy(new SolrSearchDao(client, accessConfig)); SolrDocumentList solrDocumentList = new SolrDocumentList(); solrDocumentList.add(solrDocument1); solrDocumentList.add(solrDocument2); solrDocumentList.setNumFound(100); when(queryResponse.getResults()).thenReturn(solrDocumentList); SearchResult searchResult1 = new SearchResult(); searchResult1.setId("id1"); HashMap<String, Object> source1 = new HashMap<>(); source1.put("id", "id1"); searchResult1.setSource(source1); SearchResult searchResult2 = new SearchResult(); searchResult2.setId("id2"); HashMap<String, Object> source2 = new HashMap<>(); source2.put("id", "id2"); searchResult2.setSource(source2); Map<String, Map<String, Long>> facetCounts = new HashMap<String, Map<String, Long>>() {{ put("id", new HashMap<String, Long>() {{ put("id1", 1L); put("id2", 1L); }}); }}; doReturn(facetCounts).when(solrSearchDao) .getFacetCounts(Collections.singletonList("facetField"), queryResponse); SearchResponse expectedSearchResponse = new SearchResponse(); SearchResult expectedSearchResult1 = new SearchResult(); expectedSearchResult1.setId("id1"); expectedSearchResult1.setSource(source1); SearchResult expectedSearchResult2 = new SearchResult(); expectedSearchResult2.setId("id2"); expectedSearchResult2.setSource(source2); expectedSearchResponse.setResults(Arrays.asList(expectedSearchResult1, expectedSearchResult2)); expectedSearchResponse.setTotal(100); expectedSearchResponse.setFacetCounts(facetCounts); assertEquals(expectedSearchResponse, solrSearchDao.buildSearchResponse(searchRequest, queryResponse)); }
Example 17
Source File: BlurResultHelper.java From incubator-retired-blur with Apache License 2.0 | 4 votes |
private static void convertRows(List<BlurResult> results, SolrDocumentList docResults) { for (BlurResult result : results) { docResults.add(convertRecord(result.getFetchResult().getRecordResult())); } }