Search in sources :

Example 1 with BinaryResponseWriter

use of org.apache.solr.response.BinaryResponseWriter in project lucene-solr by apache.

the class TestGroupingSearch method testGroupingSimpleFormatArrayIndexOutOfBoundsExceptionWithJavaBin.

@Test
public void testGroupingSimpleFormatArrayIndexOutOfBoundsExceptionWithJavaBin() throws Exception {
    assertU(add(doc("id", "1", "nullfirst", "1")));
    assertU(add(doc("id", "2", "nullfirst", "1")));
    assertU(add(doc("id", "3", "nullfirst", "2")));
    assertU(add(doc("id", "4", "nullfirst", "2")));
    assertU(add(doc("id", "5", "nullfirst", "2")));
    assertU(add(doc("id", "6", "nullfirst", "3")));
    assertU(commit());
    SolrQueryRequest request = req("q", "*:*", "group", "true", "group.field", "nullfirst", "group.main", "true", "wt", "javabin", "start", "4", "rows", "10");
    SolrQueryResponse response = new SolrQueryResponse();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        SolrRequestInfo.setRequestInfo(new SolrRequestInfo(request, response));
        String handlerName = request.getParams().get(CommonParams.QT);
        h.getCore().execute(h.getCore().getRequestHandler(handlerName), request, response);
        BinaryResponseWriter responseWriter = new BinaryResponseWriter();
        responseWriter.write(out, request, response);
    } finally {
        request.close();
        SolrRequestInfo.clearRequestInfo();
    }
    assertEquals(6, ((ResultContext) response.getResponse()).getDocList().matches());
    new BinaryResponseParser().processResponse(new ByteArrayInputStream(out.toByteArray()), "");
    out.close();
}
Also used : ResultContext(org.apache.solr.response.ResultContext) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) BinaryResponseParser(org.apache.solr.client.solrj.impl.BinaryResponseParser) ByteArrayInputStream(java.io.ByteArrayInputStream) BinaryResponseWriter(org.apache.solr.response.BinaryResponseWriter) SolrRequestInfo(org.apache.solr.request.SolrRequestInfo) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 2 with BinaryResponseWriter

use of org.apache.solr.response.BinaryResponseWriter in project lucene-solr by apache.

the class ExportWriter method write.

public void write(OutputStream os) throws IOException {
    QueryResponseWriter rw = req.getCore().getResponseWriters().get(wt);
    if (rw instanceof BinaryResponseWriter) {
        //todo add support for other writers after testing
        writer = new JavaBinCodec(os, null);
    } else {
        respWriter = new OutputStreamWriter(os, StandardCharsets.UTF_8);
        writer = JSONResponseWriter.getPushWriter(respWriter, req, res);
    }
    Exception exception = res.getException();
    if (exception != null) {
        if (!(exception instanceof IgnoreException)) {
            writeException(exception, writer, false);
        }
        return;
    }
    SolrRequestInfo info = SolrRequestInfo.getRequestInfo();
    SortSpec sortSpec = info.getResponseBuilder().getSortSpec();
    if (sortSpec == null) {
        writeException((new IOException(new SyntaxError("No sort criteria was provided."))), writer, true);
        return;
    }
    SolrIndexSearcher searcher = req.getSearcher();
    Sort sort = searcher.weightSort(sortSpec.getSort());
    if (sort == null) {
        writeException((new IOException(new SyntaxError("No sort criteria was provided."))), writer, true);
        return;
    }
    if (sort != null && sort.needsScores()) {
        writeException((new IOException(new SyntaxError("Scoring is not currently supported with xsort."))), writer, true);
        return;
    }
    // This came to light in the very artifical case of indexing a single doc to Cloud.
    if (req.getContext().get("totalHits") != null) {
        totalHits = ((Integer) req.getContext().get("totalHits")).intValue();
        sets = (FixedBitSet[]) req.getContext().get("export");
        if (sets == null) {
            writeException((new IOException(new SyntaxError("xport RankQuery is required for xsort: rq={!xport}"))), writer, true);
            return;
        }
    }
    SolrParams params = req.getParams();
    String fl = params.get("fl");
    String[] fields = null;
    if (fl == null) {
        writeException((new IOException(new SyntaxError("export field list (fl) must be specified."))), writer, true);
        return;
    } else {
        fields = fl.split(",");
        for (int i = 0; i < fields.length; i++) {
            fields[i] = fields[i].trim();
            if (fields[i].equals("score")) {
                writeException((new IOException(new SyntaxError("Scoring is not currently supported with xsort."))), writer, true);
                return;
            }
        }
    }
    try {
        fieldWriters = getFieldWriters(fields, req.getSearcher());
    } catch (Exception e) {
        writeException(e, writer, true);
        return;
    }
    writer.writeMap(m -> {
        m.put("responseHeader", singletonMap("status", 0));
        m.put("response", (MapWriter) mw -> {
            mw.put("numFound", totalHits);
            mw.put("docs", (IteratorWriter) iw -> writeDocs(req, iw, sort));
        });
    });
}
Also used : BitSetIterator(org.apache.lucene.util.BitSetIterator) Date(java.util.Date) EntryWriter(org.apache.solr.common.MapWriter.EntryWriter) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher) IndexableField(org.apache.lucene.index.IndexableField) JSONResponseWriter(org.apache.solr.response.JSONResponseWriter) BoolField(org.apache.solr.schema.BoolField) StrField(org.apache.solr.schema.StrField) LoggerFactory(org.slf4j.LoggerFactory) LongValues(org.apache.lucene.util.LongValues) SolrParams(org.apache.solr.common.params.SolrParams) Collections.singletonList(java.util.Collections.singletonList) SolrException(org.apache.solr.common.SolrException) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) SortField(org.apache.lucene.search.SortField) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) PrintWriter(java.io.PrintWriter) MapWriter(org.apache.solr.common.MapWriter) Sort(org.apache.lucene.search.Sort) BytesRef(org.apache.lucene.util.BytesRef) SolrCore(org.apache.solr.core.SolrCore) MethodHandles(java.lang.invoke.MethodHandles) StandardCharsets(java.nio.charset.StandardCharsets) Utils.makeMap(org.apache.solr.common.util.Utils.makeMap) List(java.util.List) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) LeafReader(org.apache.lucene.index.LeafReader) IteratorWriter(org.apache.solr.common.IteratorWriter) JavaBinCodec(org.apache.solr.common.util.JavaBinCodec) TrieDateField(org.apache.solr.schema.TrieDateField) PushWriter(org.apache.solr.common.PushWriter) NumericDocValues(org.apache.lucene.index.NumericDocValues) QueryResponseWriter(org.apache.solr.response.QueryResponseWriter) FieldType(org.apache.solr.schema.FieldType) FixedBitSet(org.apache.lucene.util.FixedBitSet) CharsRefBuilder(org.apache.lucene.util.CharsRefBuilder) SortSpec(org.apache.solr.search.SortSpec) BinaryResponseParser(org.apache.solr.client.solrj.impl.BinaryResponseParser) SchemaField(org.apache.solr.schema.SchemaField) TrieFloatField(org.apache.solr.schema.TrieFloatField) TrieLongField(org.apache.solr.schema.TrieLongField) SyntaxError(org.apache.solr.search.SyntaxError) SortedSetDocValues(org.apache.lucene.index.SortedSetDocValues) TrieIntField(org.apache.solr.schema.TrieIntField) OutputStreamWriter(java.io.OutputStreamWriter) Collections.singletonMap(java.util.Collections.singletonMap) SortedDocValues(org.apache.lucene.index.SortedDocValues) SolrRequestInfo(org.apache.solr.request.SolrRequestInfo) DocIdSetIterator(org.apache.lucene.search.DocIdSetIterator) OutputStream(java.io.OutputStream) ArrayUtil(org.apache.lucene.util.ArrayUtil) Logger(org.slf4j.Logger) MultiDocValues(org.apache.lucene.index.MultiDocValues) BinaryResponseWriter(org.apache.solr.response.BinaryResponseWriter) IOException(java.io.IOException) TrieDoubleField(org.apache.solr.schema.TrieDoubleField) IndexSchema(org.apache.solr.schema.IndexSchema) DocValues(org.apache.lucene.index.DocValues) Closeable(java.io.Closeable) BinaryResponseWriter(org.apache.solr.response.BinaryResponseWriter) IOException(java.io.IOException) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher) SolrException(org.apache.solr.common.SolrException) IOException(java.io.IOException) JavaBinCodec(org.apache.solr.common.util.JavaBinCodec) SyntaxError(org.apache.solr.search.SyntaxError) FixedBitSet(org.apache.lucene.util.FixedBitSet) IteratorWriter(org.apache.solr.common.IteratorWriter) QueryResponseWriter(org.apache.solr.response.QueryResponseWriter) Sort(org.apache.lucene.search.Sort) SolrParams(org.apache.solr.common.params.SolrParams) OutputStreamWriter(java.io.OutputStreamWriter) SolrRequestInfo(org.apache.solr.request.SolrRequestInfo) SortSpec(org.apache.solr.search.SortSpec)

Aggregations

BinaryResponseParser (org.apache.solr.client.solrj.impl.BinaryResponseParser)2 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)2 SolrRequestInfo (org.apache.solr.request.SolrRequestInfo)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Closeable (java.io.Closeable)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1 MethodHandles (java.lang.invoke.MethodHandles)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Collections.singletonList (java.util.Collections.singletonList)1 Collections.singletonMap (java.util.Collections.singletonMap)1 Date (java.util.Date)1 List (java.util.List)1 DocValues (org.apache.lucene.index.DocValues)1 IndexableField (org.apache.lucene.index.IndexableField)1 LeafReader (org.apache.lucene.index.LeafReader)1 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)1