Java Code Examples for org.apache.solr.common.SolrDocumentList#setStart()
The following examples show how to use
org.apache.solr.common.SolrDocumentList#setStart() .
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: JavaBinCodec.java From lucene-solr with Apache License 2.0 | 6 votes |
public SolrDocumentList readSolrDocumentList(DataInputInputStream dis) throws IOException { SolrDocumentList solrDocs = new SolrDocumentList(); @SuppressWarnings("unchecked") List<Object> list = (List<Object>) readVal(dis); solrDocs.setNumFound((Long) list.get(0)); solrDocs.setStart((Long) list.get(1)); solrDocs.setMaxScore((Float) list.get(2)); if (list.size() > 3) { //needed for back compatibility solrDocs.setNumFoundExact((Boolean)list.get(3)); } @SuppressWarnings("unchecked") List<SolrDocument> l = (List<SolrDocument>) readVal(dis); solrDocs.addAll(l); return solrDocs; }
Example 2
Source File: FastJavaBinDecoder.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override @SuppressWarnings({"unchecked"}) public Object readObject(StreamCodec codec, EntryImpl entry) throws IOException { SolrDocumentList solrDocs = new SolrDocumentList(); if(entry.metadata != null){ @SuppressWarnings({"rawtypes"}) List list = (List) entry.metadata; solrDocs.setNumFound((Long) list.get(0)); solrDocs.setStart((Long) list.get(1)); solrDocs.setMaxScore((Float) list.get(2)); if (list.size() > 3) { //needed for back compatibility solrDocs.setNumFoundExact((Boolean)list.get(3)); } } List<SolrDocument> l = codec.readArray(codec.dis, entry.size); solrDocs.addAll(l); return solrDocs; }
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: EmbeddedSolrServer.java From lucene-solr with Apache License 2.0 | 6 votes |
private JavaBinCodec createJavaBinCodec(final StreamingResponseCallback callback, final BinaryResponseWriter.Resolver resolver) { return new JavaBinCodec(resolver) { @Override public void writeSolrDocument(SolrDocument doc) { callback.streamSolrDocument(doc); //super.writeSolrDocument( doc, fields ); } @Override public void writeSolrDocumentList(SolrDocumentList docs) throws IOException { if (docs.size() > 0) { SolrDocumentList tmp = new SolrDocumentList(); tmp.setMaxScore(docs.getMaxScore()); tmp.setNumFound(docs.getNumFound()); tmp.setStart(docs.getStart()); docs = tmp; } callback.streamDocListInfo(docs.getNumFound(), docs.getStart(), docs.getMaxScore()); super.writeSolrDocumentList(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: 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 7
Source File: AutoCompleteSearchComponent.java From solr-autocomplete with Apache License 2.0 | 5 votes |
private void mergeDistributedResultsIntSingleResponse(ResponseBuilder rb, List<AcGroupResult> resultsToMerge, String responseTagName) { int docs = 0; float maxScore = 0.0f; // if groups have to be displayed in some custom order, other than the order specified in // ac_grouping_field_def String groupingSort = rb.req.getParams().get(AC_GROUPING_SORT_PARAM_NAME); if (groupSorts.containsKey(groupingSort)) { groupSorts.get(groupingSort).sort(rb, resultsToMerge); } SolrDocumentList docList = new SolrDocumentList(); // first find count of documents for (AcGroupResult acGroupResult : resultsToMerge) { // if slice contains more results than requested, take requested count; if it contains less results than // requested, we have to take what we got, not more docs += ((acGroupResult.getDistributedResultingDocs().size() > acGroupResult.getAcGroupingFieldValue().getRequestedCountOfSuggestions() == true) ? acGroupResult.getAcGroupingFieldValue().getRequestedCountOfSuggestions() : acGroupResult.getDistributedResultingDocs().size()); if (acGroupResult.getDistributedResultingDocs().getMaxScore() > maxScore) { maxScore = acGroupResult.getDistributedResultingDocs().getMaxScore(); } docList.addAll(acGroupResult.getDistributedResultingDocs()); } docList.setStart(0); docList.setNumFound(docs); rb.rsp.add(responseTagName, docList); }
Example 8
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 9
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 10
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 11
Source File: BlurResultHelper.java From incubator-retired-blur with Apache License 2.0 | 4 votes |
private static void convertMetadata(BlurResults results, SolrDocumentList docResults) { docResults.setNumFound(results.getTotalResults()); docResults.setStart(results.getQuery().getStart()); }