use of org.apache.solr.common.util.ContentStream in project lucene-solr by apache.
the class XsltUpdateRequestHandlerTest method testUpdate.
@Test
public void testUpdate() throws Exception {
String xml = "<random>" + " <document>" + " <node name=\"id\" value=\"12345\"/>" + " <node name=\"name\" value=\"kitten\"/>" + " <node name=\"text\" enhance=\"3\" value=\"some other day\"/>" + " <node name=\"title\" enhance=\"4\" value=\"A story\"/>" + " <node name=\"timestamp\" enhance=\"5\" value=\"2011-07-01T10:31:57.140Z\"/>" + " </document>" + "</random>";
Map<String, String> args = new HashMap<>();
args.put(CommonParams.TR, "xsl-update-handler-test.xsl");
SolrCore core = h.getCore();
LocalSolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
ArrayList<ContentStream> streams = new ArrayList<>();
streams.add(new ContentStreamBase.StringStream(xml));
req.setContentStreams(streams);
SolrQueryResponse rsp = new SolrQueryResponse();
UpdateRequestHandler handler = new UpdateRequestHandler();
handler.init(new NamedList<String>());
handler.handleRequestBody(req, rsp);
StringWriter sw = new StringWriter(32000);
QueryResponseWriter responseWriter = core.getQueryResponseWriter(req);
responseWriter.write(sw, req, rsp);
req.close();
String response = sw.toString();
assertU(response);
assertU(commit());
assertQ("test document was correctly committed", req("q", "*:*"), "//result[@numFound='1']", "//int[@name='id'][.='12345']");
}
use of org.apache.solr.common.util.ContentStream in project lucene-solr by apache.
the class MBeansHandlerTest method testDiff.
@Test
public void testDiff() throws Exception {
String xml = h.query(req(CommonParams.QT, "/admin/mbeans", "stats", "true", CommonParams.WT, "xml"));
List<ContentStream> streams = new ArrayList<>();
streams.add(new ContentStreamBase.StringStream(xml));
LocalSolrQueryRequest req = lrf.makeRequest(CommonParams.QT, "/admin/mbeans", "stats", "true", CommonParams.WT, "xml", "diff", "true");
req.setContentStreams(streams);
xml = h.query(req);
NamedList<NamedList<NamedList<Object>>> diff = SolrInfoMBeanHandler.fromXML(xml);
// The stats bean for SolrInfoMBeanHandler
NamedList stats = (NamedList) diff.get("ADMIN").get("/admin/mbeans").get("stats");
//System.out.println("stats:"+stats);
Pattern p = Pattern.compile("Was: (?<was>[0-9]+), Now: (?<now>[0-9]+), Delta: (?<delta>[0-9]+)");
String response = stats.get("ADMIN./admin/mbeans.requests").toString();
Matcher m = p.matcher(response);
if (!m.matches()) {
fail("Response did not match pattern: " + response);
}
assertEquals(1, Integer.parseInt(m.group("delta")));
int was = Integer.parseInt(m.group("was"));
int now = Integer.parseInt(m.group("now"));
assertEquals(1, now - was);
xml = h.query(req(CommonParams.QT, "/admin/mbeans", "stats", "true", "key", "org.apache.solr.handler.admin.CollectionsHandler"));
NamedList<NamedList<NamedList<Object>>> nl = SolrInfoMBeanHandler.fromXML(xml);
assertNotNull(nl.get("ADMIN").get("org.apache.solr.handler.admin.CollectionsHandler"));
}
use of org.apache.solr.common.util.ContentStream in project lucene-solr by apache.
the class MoreLikeThisHandlerTest method testInterface.
@Test
public void testInterface() throws Exception {
SolrCore core = h.getCore();
MoreLikeThisHandler mlt = new MoreLikeThisHandler();
ModifiableSolrParams params = new ModifiableSolrParams();
SolrQueryRequestBase req = new SolrQueryRequestBase(core, params) {
};
// requires 'q' or single content stream
try {
mlt.handleRequestBody(req, new SolrQueryResponse());
}// expected
catch (Exception ex) {
}
// requires 'q' or single content stream
try {
ArrayList<ContentStream> streams = new ArrayList<>(2);
streams.add(new ContentStreamBase.StringStream("hello"));
streams.add(new ContentStreamBase.StringStream("there"));
req.setContentStreams(streams);
mlt.handleRequestBody(req, new SolrQueryResponse());
}// expected
catch (Exception ex) {
} finally {
req.close();
}
assertU(adoc("id", "42", "name", "Tom Cruise", "subword", "Top Gun", "subword", "Risky Business", "subword", "The Color of Money", "subword", "Minority Report", "subword", "Days of Thunder", "subword", "Eyes Wide Shut", "subword", "Far and Away", "foo_ti", "10"));
assertU(adoc("id", "43", "name", "Tom Hanks", "subword", "The Green Mile", "subword", "Forest Gump", "subword", "Philadelphia Story", "subword", "Big", "subword", "Cast Away", "foo_ti", "10"));
assertU(adoc("id", "44", "name", "Harrison Ford", "subword", "Star Wars", "subword", "Indiana Jones", "subword", "Patriot Games", "subword", "Regarding Henry"));
assertU(adoc("id", "45", "name", "George Harrison", "subword", "Yellow Submarine", "subword", "Help", "subword", "Magical Mystery Tour", "subword", "Sgt. Peppers Lonley Hearts Club Band"));
assertU(adoc("id", "46", "name", "Nicole Kidman", "subword", "Batman", "subword", "Days of Thunder", "subword", "Eyes Wide Shut", "subword", "Far and Away"));
assertU(commit());
params.set(CommonParams.Q, "id:42");
params.set(MoreLikeThisParams.MLT, "true");
params.set(MoreLikeThisParams.SIMILARITY_FIELDS, "name,subword");
params.set(MoreLikeThisParams.INTERESTING_TERMS, "details");
params.set(MoreLikeThisParams.MIN_TERM_FREQ, "1");
params.set(MoreLikeThisParams.MIN_DOC_FREQ, "1");
params.set("indent", "true");
SolrQueryRequest mltreq = new LocalSolrQueryRequest(core, params);
assertQ("morelikethis - tom cruise", mltreq, "//result/doc[1]/int[@name='id'][.='46']", "//result/doc[2]/int[@name='id'][.='43']");
params.set(MoreLikeThisParams.BOOST, "true");
mltreq.close();
mltreq = new LocalSolrQueryRequest(core, params);
assertQ("morelikethis - tom cruise", mltreq, "//result/doc[1]/int[@name='id'][.='46']", "//result/doc[2]/int[@name='id'][.='43']");
params.set(CommonParams.Q, "id:44");
mltreq.close();
mltreq = new LocalSolrQueryRequest(h.getCore(), params);
assertQ("morelike this - harrison ford", mltreq, "//result/doc[1]/int[@name='id'][.='45']");
// test MoreLikeThis debug
params.set(CommonParams.DEBUG_QUERY, "true");
mltreq.close();
mltreq = new LocalSolrQueryRequest(h.getCore(), params);
assertQ("morelike this - harrison ford", mltreq, "//lst[@name='debug']/lst[@name='moreLikeThis']/lst[@name='44']/str[@name='rawMLTQuery']", "//lst[@name='debug']/lst[@name='moreLikeThis']/lst[@name='44']/str[@name='boostedMLTQuery']", "//lst[@name='debug']/lst[@name='moreLikeThis']/lst[@name='44']/str[@name='realMLTQuery']", "//lst[@name='debug']/lst[@name='moreLikeThis']/lst[@name='44']/lst[@name='explain']/str[@name='45']");
// test that qparser plugins work
params.remove(CommonParams.DEBUG_QUERY);
params.set(CommonParams.Q, "{!field f=id}44");
mltreq.close();
mltreq = new LocalSolrQueryRequest(h.getCore(), params);
assertQ(mltreq, "//result/doc[1]/int[@name='id'][.='45']");
params.set(CommonParams.Q, "id:42");
params.set(MoreLikeThisParams.QF, "name^5.0 subword^0.1");
mltreq.close();
mltreq = new LocalSolrQueryRequest(h.getCore(), params);
assertQ("morelikethis with weights", mltreq, "//result/doc[1]/int[@name='id'][.='43']", "//result/doc[2]/int[@name='id'][.='46']");
// test that qparser plugins work w/ the MoreLikeThisHandler
params.set(CommonParams.QT, "/mlt");
params.set(CommonParams.Q, "{!field f=id}44");
mltreq.close();
mltreq = new LocalSolrQueryRequest(h.getCore(), params);
assertQ(mltreq, "//result/doc[1]/int[@name='id'][.='45']");
// test that debugging works (test for MoreLikeThis*Handler*)
params.set(CommonParams.QT, "/mlt");
params.set(CommonParams.DEBUG_QUERY, "true");
mltreq.close();
mltreq = new LocalSolrQueryRequest(h.getCore(), params);
assertQ(mltreq, "//result/doc[1]/int[@name='id'][.='45']", "//lst[@name='debug']/lst[@name='explain']");
// params.put(MoreLikeThisParams.QF,new String[]{"foo_ti"});
// String response = h.query(mltreq);
// System.out.println(response);
mltreq.close();
}
use of org.apache.solr.common.util.ContentStream in project lucene-solr by apache.
the class TestCSVLoader method loadLocal.
void loadLocal(String... args) throws Exception {
LocalSolrQueryRequest req = (LocalSolrQueryRequest) req(args);
// TODO: stop using locally defined streams once stream.file and
// stream.body work everywhere
List<ContentStream> cs = new ArrayList<>(1);
ContentStreamBase f = new ContentStreamBase.FileStream(new File(filename));
f.setContentType("text/csv");
cs.add(f);
req.setContentStreams(cs);
h.query("/update", req);
}
use of org.apache.solr.common.util.ContentStream in project lucene-solr by apache.
the class TestRerankBase method bulkIndex.
protected static void bulkIndex(String filePath) throws Exception {
final SolrQueryRequestBase req = lrf.makeRequest(CommonParams.STREAM_CONTENTTYPE, "application/xml");
final List<ContentStream> streams = new ArrayList<ContentStream>();
final File file = new File(filePath);
streams.add(new ContentStreamBase.FileStream(file));
req.setContentStreams(streams);
try {
final SolrQueryResponse res = new SolrQueryResponse();
h.updater.handleRequest(req, res);
} catch (final Throwable ex) {
// Ignore. Just log the exception and go to the next file
log.error(ex.getMessage(), ex);
}
assertU(commit());
}
Aggregations