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();
}
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();
}
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();
}
}
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();
}
}
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);
}
}
Aggregations