use of org.apache.solr.request.LocalSolrQueryRequest in project lucene-solr by apache.
the class TolerantUpdateProcessorTest method add.
protected SolrQueryResponse add(final String chain, SolrParams requestParams, final Collection<SolrInputDocument> docs) throws IOException {
SolrCore core = h.getCore();
UpdateRequestProcessorChain pc = core.getUpdateProcessingChain(chain);
assertNotNull("No Chain named: " + chain, pc);
SolrQueryResponse rsp = new SolrQueryResponse();
rsp.add("responseHeader", new SimpleOrderedMap<Object>());
if (requestParams == null) {
requestParams = new ModifiableSolrParams();
}
SolrQueryRequest req = new LocalSolrQueryRequest(core, requestParams);
UpdateRequestProcessor processor = null;
try {
processor = pc.createProcessor(req, rsp);
for (SolrInputDocument doc : docs) {
AddUpdateCommand cmd = new AddUpdateCommand(req);
cmd.solrDoc = doc;
processor.processAdd(cmd);
}
processor.finish();
} finally {
IOUtils.closeQuietly(processor);
req.close();
}
return rsp;
}
use of org.apache.solr.request.LocalSolrQueryRequest in project lucene-solr by apache.
the class UpdateProcessorTestBase method processAdd.
/**
* Runs a document through the specified chain, and returns the final
* document used when the chain is completed (NOTE: some chains may
* modify the document in place
*/
protected SolrInputDocument processAdd(final String chain, final SolrParams requestParams, final SolrInputDocument docIn) throws IOException {
SolrCore core = h.getCore();
UpdateRequestProcessorChain pc = core.getUpdateProcessingChain(chain);
assertNotNull("No Chain named: " + chain, pc);
SolrQueryResponse rsp = new SolrQueryResponse();
SolrQueryRequest req = new LocalSolrQueryRequest(core, requestParams);
try {
SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
AddUpdateCommand cmd = new AddUpdateCommand(req);
cmd.solrDoc = docIn;
UpdateRequestProcessor processor = pc.createProcessor(req, rsp);
if (null != processor) {
// test chain might be empty or short circuited.
processor.processAdd(cmd);
}
return cmd.solrDoc;
} finally {
SolrRequestInfo.clearRequestInfo();
req.close();
}
}
use of org.apache.solr.request.LocalSolrQueryRequest in project lucene-solr by apache.
the class UpdateProcessorTestBase method processDeleteById.
protected void processDeleteById(final String chain, String id) throws IOException {
SolrCore core = h.getCore();
UpdateRequestProcessorChain pc = core.getUpdateProcessingChain(chain);
assertNotNull("No Chain named: " + chain, pc);
SolrQueryResponse rsp = new SolrQueryResponse();
SolrQueryRequest req = new LocalSolrQueryRequest(core, new ModifiableSolrParams());
DeleteUpdateCommand cmd = new DeleteUpdateCommand(req);
cmd.setId(id);
UpdateRequestProcessor processor = pc.createProcessor(req, rsp);
try {
processor.processDelete(cmd);
} finally {
req.close();
}
}
use of org.apache.solr.request.LocalSolrQueryRequest in project lucene-solr by apache.
the class StatsComponentTest method testFieldStatisticsResultsStringFieldAlwaysMissing.
public void testFieldStatisticsResultsStringFieldAlwaysMissing() throws Exception {
SolrCore core = h.getCore();
assertU(adoc("id", "1"));
assertU(adoc("id", "2"));
assertU(commit());
assertU(adoc("id", "3"));
assertU(adoc("id", "4"));
assertU(commit());
Map<String, String> args = new HashMap<>();
args.put(CommonParams.Q, "*:*");
args.put(StatsParams.STATS, "true");
args.put(StatsParams.STATS_FIELD, "active_s");
args.put("indent", "true");
SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
assertQ("test string statistics values", req, "//lst[@name='active_s']/long[@name='count'][.='0']", "//lst[@name='active_s']/long[@name='missing'][.='4']", "//lst[@name='active_s']/null[@name='min']", "//lst[@name='active_s']/null[@name='max']", // if new stats are supported, this will break - update test to assert values for each
"count(//lst[@name='active_s']/*)=4");
assertQ("test string statistics values", req("q", "*:*", "stats", "true", "stats.field", "{!cardinality=true}active_s"), "//lst[@name='active_s']/long[@name='cardinality'][.='0']");
}
use of org.apache.solr.request.LocalSolrQueryRequest in project lucene-solr by apache.
the class StatsComponentTest method testFieldStatisticsDocValuesAndMultiValued.
// SOLR-6024
public void testFieldStatisticsDocValuesAndMultiValued() throws Exception {
SolrCore core = h.getCore();
// precondition for the test
SchemaField catDocValues = core.getLatestSchema().getField("cat_docValues");
assertTrue("schema no longer satisfies test requirements: cat_docValues no longer multivalued", catDocValues.multiValued());
assertTrue("schema no longer satisfies test requirements: cat_docValues fieldtype no longer single valued", !catDocValues.getType().isMultiValued());
assertTrue("schema no longer satisfies test requirements: cat_docValues no longer has docValues", catDocValues.hasDocValues());
List<FldType> types = new ArrayList<>();
types.add(new FldType("id", ONE_ONE, new SVal('A', 'Z', 4, 4)));
types.add(new FldType("cat_docValues", new IRange(2, 2), new SVal('a', 'z', 1, 30)));
Doc d1 = createDoc(types);
d1.getValues("id").set(0, "1");
d1.getValues("cat_docValues").set(0, "test");
d1.getValues("cat_docValues").set(1, "testtw");
updateJ(toJSON(d1), null);
Doc d2 = createDoc(types);
d2.getValues("id").set(0, "2");
d2.getValues("cat_docValues").set(0, "test");
d2.getValues("cat_docValues").set(1, "testtt");
updateJ(toJSON(d2), null);
assertU(commit());
Map<String, String> args = new HashMap<>();
args.put(CommonParams.Q, "*:*");
args.put(StatsParams.STATS, "true");
args.put(StatsParams.STATS_FIELD, "cat_docValues");
args.put("indent", "true");
SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
assertQ("test min/max on docValues and multiValued", req, "//lst[@name='cat_docValues']/str[@name='min'][.='test']", "//lst[@name='cat_docValues']/str[@name='max'][.='testtw']");
assertQ("cardinality", req("q", "*:*", "stats", "true", "stats.field", "{!cardinality=true}cat_docValues"), "//lst[@name='cat_docValues']/long[@name='cardinality'][.='3']");
}
Aggregations