Search in sources :

Example 41 with LocalSolrQueryRequest

use of org.apache.solr.request.LocalSolrQueryRequest in project lucene-solr by apache.

the class TestBinaryResponseWriter method testUUID.

/**
   * Tests known types implementation by asserting correct encoding/decoding of UUIDField
   */
public void testUUID() throws Exception {
    String s = UUID.randomUUID().toString().toLowerCase(Locale.ROOT);
    assertU(adoc("id", "101", "uuid", s));
    assertU(commit());
    LocalSolrQueryRequest req = lrf.makeRequest("q", "*:*");
    SolrQueryResponse rsp = h.queryAndResponse(req.getParams().get(CommonParams.QT), req);
    BinaryQueryResponseWriter writer = (BinaryQueryResponseWriter) h.getCore().getQueryResponseWriter("javabin");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    writer.write(baos, req, rsp);
    NamedList res = (NamedList) new JavaBinCodec().unmarshal(new ByteArrayInputStream(baos.toByteArray()));
    SolrDocumentList docs = (SolrDocumentList) res.get("response");
    for (Object doc : docs) {
        SolrDocument document = (SolrDocument) doc;
        assertEquals("Returned object must be a string", "java.lang.String", document.getFieldValue("uuid").getClass().getName());
        assertEquals("Wrong UUID string returned", s, document.getFieldValue("uuid"));
    }
    req.close();
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrDocument(org.apache.solr.common.SolrDocument) ByteArrayInputStream(java.io.ByteArrayInputStream) NamedList(org.apache.solr.common.util.NamedList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SolrDocumentList(org.apache.solr.common.SolrDocumentList) JavaBinCodec(org.apache.solr.common.util.JavaBinCodec)

Example 42 with LocalSolrQueryRequest

use of org.apache.solr.request.LocalSolrQueryRequest in project lucene-solr by apache.

the class TestBinaryResponseWriter method testResolverSolrDocumentPartialFields.

public void testResolverSolrDocumentPartialFields() throws Exception {
    LocalSolrQueryRequest req = lrf.makeRequest("q", "*:*", "fl", "id,xxx,ddd_s");
    SolrDocument in = new SolrDocument();
    in.addField("id", 345);
    in.addField("aaa_s", "aaa");
    in.addField("bbb_s", "bbb");
    in.addField("ccc_s", "ccc");
    in.addField("ddd_s", "ddd");
    in.addField("eee_s", "eee");
    Resolver r = new Resolver(req, new SolrReturnFields(req));
    Object o = r.resolve(in, new JavaBinCodec());
    assertNotNull("obj is null", o);
    assertTrue("obj is not doc", o instanceof SolrDocument);
    SolrDocument out = new SolrDocument();
    for (Map.Entry<String, Object> e : in) {
        if (r.isWritable(e.getKey()))
            out.put(e.getKey(), e.getValue());
    }
    assertTrue("id not found", out.getFieldNames().contains("id"));
    assertTrue("ddd_s not found", out.getFieldNames().contains("ddd_s"));
    assertEquals("Wrong number of fields found", 2, out.getFieldNames().size());
    req.close();
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrDocument(org.apache.solr.common.SolrDocument) Resolver(org.apache.solr.response.BinaryResponseWriter.Resolver) Map(java.util.Map) SolrReturnFields(org.apache.solr.search.SolrReturnFields) JavaBinCodec(org.apache.solr.common.util.JavaBinCodec)

Example 43 with LocalSolrQueryRequest

use of org.apache.solr.request.LocalSolrQueryRequest in project lucene-solr by apache.

the class UpdateLog method doClose.

private void doClose(TransactionLog theLog, boolean writeCommit) {
    if (theLog != null) {
        if (writeCommit) {
            // record a commit
            log.info("Recording current closed for " + uhandler.core + " log=" + theLog);
            CommitUpdateCommand cmd = new CommitUpdateCommand(new LocalSolrQueryRequest(uhandler.core, new ModifiableSolrParams((SolrParams) null)), false);
            theLog.writeCommit(cmd, operationFlags);
        }
        theLog.deleteOnClose = false;
        theLog.decref();
        theLog.forceClose();
    }
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 44 with LocalSolrQueryRequest

use of org.apache.solr.request.LocalSolrQueryRequest in project lucene-solr by apache.

the class UpdateLog method copyOverOldUpdates.

/**
   * Copy over updates from prevTlog or last tlog (in tlog folder) to a new tlog
   * @param commitVersion any updates that have version larger than the commitVersion will be copied over
   */
public void copyOverOldUpdates(long commitVersion) {
    TransactionLog oldTlog = prevTlog;
    if (oldTlog == null && !logs.isEmpty()) {
        oldTlog = logs.getFirst();
    }
    if (oldTlog == null || oldTlog.refcount.get() == 0) {
        return;
    }
    try {
        if (oldTlog.endsWithCommit()) {
            return;
        }
    } catch (IOException e) {
        log.warn("Exception reading log", e);
        return;
    }
    SolrQueryRequest req = new LocalSolrQueryRequest(uhandler.core, new ModifiableSolrParams());
    TransactionLog.LogReader logReader = oldTlog.getReader(0);
    Object o = null;
    try {
        while ((o = logReader.next()) != null) {
            try {
                List entry = (List) o;
                int operationAndFlags = (Integer) entry.get(0);
                int oper = operationAndFlags & OPERATION_MASK;
                long version = (Long) entry.get(1);
                if (Math.abs(version) > commitVersion) {
                    switch(oper) {
                        case UpdateLog.UPDATE_INPLACE:
                        case UpdateLog.ADD:
                            {
                                AddUpdateCommand cmd = convertTlogEntryToAddUpdateCommand(req, entry, oper, version);
                                cmd.setFlags(UpdateCommand.IGNORE_AUTOCOMMIT);
                                add(cmd);
                                break;
                            }
                        case UpdateLog.DELETE:
                            {
                                byte[] idBytes = (byte[]) entry.get(2);
                                DeleteUpdateCommand cmd = new DeleteUpdateCommand(req);
                                cmd.setIndexedId(new BytesRef(idBytes));
                                cmd.setVersion(version);
                                cmd.setFlags(UpdateCommand.IGNORE_AUTOCOMMIT);
                                delete(cmd);
                                break;
                            }
                        case UpdateLog.DELETE_BY_QUERY:
                            {
                                String query = (String) entry.get(2);
                                DeleteUpdateCommand cmd = new DeleteUpdateCommand(req);
                                cmd.query = query;
                                cmd.setVersion(version);
                                cmd.setFlags(UpdateCommand.IGNORE_AUTOCOMMIT);
                                deleteByQuery(cmd);
                                break;
                            }
                        default:
                            throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown Operation! " + oper);
                    }
                }
            } catch (ClassCastException e) {
                log.warn("Unexpected log entry or corrupt log.  Entry=" + o, e);
            }
        }
        // Prev tlog will be closed, so nullify prevMap
        if (prevTlog == oldTlog) {
            prevMap = null;
        }
    } catch (IOException e) {
        log.error("Exception reading versions from log", e);
    } catch (InterruptedException e) {
        log.warn("Exception reading log", e);
    } finally {
        if (logReader != null)
            logReader.close();
    }
}
Also used : IOException(java.io.IOException) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) BytesRef(org.apache.lucene.util.BytesRef) SolrException(org.apache.solr.common.SolrException)

Example 45 with LocalSolrQueryRequest

use of org.apache.solr.request.LocalSolrQueryRequest in project lucene-solr by apache.

the class SmileWriterTest method test10Docs.

@Test
public void test10Docs() throws IOException {
    SolrQueryResponse response = new SolrQueryResponse();
    SolrDocumentList l = constructSolrDocList(response);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    new SmileResponseWriter().write(baos, new LocalSolrQueryRequest(null, new ModifiableSolrParams()), response);
    byte[] bytes = baos.toByteArray();
    Map m = (Map) decodeSmile(new ByteArrayInputStream(bytes, 0, bytes.length));
    m = (Map) m.get("results");
    List lst = (List) m.get("docs");
    assertEquals(lst.size(), 10);
    for (int i = 0; i < lst.size(); i++) {
        m = (Map) lst.get(i);
        SolrDocument d = new SolrDocument();
        d.putAll(m);
        compareSolrDocument(l.get(i), d);
    }
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrDocument(org.apache.solr.common.SolrDocument) ByteArrayInputStream(java.io.ByteArrayInputStream) SolrDocumentList(org.apache.solr.common.SolrDocumentList) ArrayList(java.util.ArrayList) NamedList(org.apache.solr.common.util.NamedList) List(java.util.List) SolrDocumentList(org.apache.solr.common.SolrDocumentList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) Test(org.junit.Test)

Aggregations

LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)107 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)61 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)49 SolrCore (org.apache.solr.core.SolrCore)47 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)41 Test (org.junit.Test)41 HashMap (java.util.HashMap)32 NamedList (org.apache.solr.common.util.NamedList)26 ArrayList (java.util.ArrayList)23 MapSolrParams (org.apache.solr.common.params.MapSolrParams)21 SolrException (org.apache.solr.common.SolrException)18 List (java.util.List)15 LinkedHashMap (java.util.LinkedHashMap)11 SolrParams (org.apache.solr.common.params.SolrParams)10 SearchComponent (org.apache.solr.handler.component.SearchComponent)10 SolrRequestHandler (org.apache.solr.request.SolrRequestHandler)10 AddUpdateCommand (org.apache.solr.update.AddUpdateCommand)10 Map (java.util.Map)9 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)9 IOException (java.io.IOException)8