use of org.apache.solr.common.params.MapSolrParams 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.params.MapSolrParams in project lucene-solr by apache.
the class DirectUpdateHandlerTest method testDeleteRollback.
@Test
public void testDeleteRollback() throws Exception {
// re-init the core
deleteCore();
initCore("solrconfig.xml", "schema12.xml");
assertU(adoc("id", "A"));
assertU(adoc("id", "B"));
// commit "A", "B"
SolrCore core = h.getCore();
UpdateHandler updater = core.getUpdateHandler();
assertTrue(updater instanceof DirectUpdateHandler2);
DirectUpdateHandler2 duh2 = (DirectUpdateHandler2) updater;
SolrQueryRequest ureq = req();
CommitUpdateCommand cmtCmd = new CommitUpdateCommand(ureq, false);
cmtCmd.waitSearcher = true;
assertEquals(2, duh2.addCommands.longValue());
assertEquals(2, duh2.addCommandsCumulative.getCount());
assertEquals(0, duh2.commitCommands.getCount());
updater.commit(cmtCmd);
assertEquals(0, duh2.addCommands.longValue());
assertEquals(2, duh2.addCommandsCumulative.getCount());
assertEquals(1, duh2.commitCommands.getCount());
ureq.close();
// search - "A","B" should be found.
Map<String, String> args = new HashMap<>();
args.put(CommonParams.Q, "id:A OR id:B");
args.put("indent", "true");
SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
assertQ("\"A\" and \"B\" should be found.", req, "//*[@numFound='2']", "//result/doc[1]/str[@name='id'][.='A']", "//result/doc[2]/str[@name='id'][.='B']");
// delete "B"
assertU(delI("B"));
// search - "A","B" should be found.
assertQ("\"A\" and \"B\" should be found.", req, "//*[@numFound='2']", "//result/doc[1]/str[@name='id'][.='A']", "//result/doc[2]/str[@name='id'][.='B']");
// rollback "B"
ureq = req();
RollbackUpdateCommand rbkCmd = new RollbackUpdateCommand(ureq);
assertEquals(1, duh2.deleteByIdCommands.longValue());
assertEquals(1, duh2.deleteByIdCommandsCumulative.getCount());
assertEquals(0, duh2.rollbackCommands.getCount());
updater.rollback(rbkCmd);
ureq.close();
assertEquals(0, duh2.deleteByIdCommands.longValue());
assertEquals(0, duh2.deleteByIdCommandsCumulative.getCount());
assertEquals(1, duh2.rollbackCommands.getCount());
// search - "B" should be found.
assertQ("\"B\" should be found.", req, "//*[@numFound='2']", "//result/doc[1]/str[@name='id'][.='A']", "//result/doc[2]/str[@name='id'][.='B']");
// Add a doc after the rollback to make sure we can continue to add/delete documents
// after a rollback as normal
assertU(adoc("id", "ZZZ"));
assertU(commit());
assertQ("\"ZZZ\" must be found.", req("q", "id:ZZZ"), "//*[@numFound='1']", "//result/doc[1]/str[@name='id'][.='ZZZ']");
}
use of org.apache.solr.common.params.MapSolrParams in project lucene-solr by apache.
the class CopyFieldTest method testSourceGlobMatchesNoDynamicOrExplicitField.
@Test
public void testSourceGlobMatchesNoDynamicOrExplicitField() {
// SOLR-4650: copyField source globs should not have to match an explicit or dynamic field
SolrCore core = h.getCore();
IndexSchema schema = core.getLatestSchema();
assertNull("'testing123_*' should not be (or match) a dynamic or explicit field", schema.getFieldOrNull("testing123_*"));
assertTrue("schema should contain dynamic field '*_s'", schema.getDynamicPattern("*_s").equals("*_s"));
assertU(adoc("id", "5", "sku1", "10-1839ACX-93", "testing123_s", "AAM46"));
assertU(commit());
Map<String, String> args = new HashMap<>();
args.put(CommonParams.Q, "text:AAM46");
args.put("indent", "true");
SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
assertQ("sku2 copied to text", req, "//*[@numFound='1']", "//result/doc[1]/int[@name='id'][.='5']");
}
use of org.apache.solr.common.params.MapSolrParams in project lucene-solr by apache.
the class CopyFieldTest method testExplicitSourceGlob.
@Test
public void testExplicitSourceGlob() {
SolrCore core = h.getCore();
IndexSchema schema = core.getLatestSchema();
assertTrue("schema should contain explicit field 'sku1'", schema.getFields().containsKey("sku1"));
assertTrue("schema should contain explicit field 'sku2'", schema.getFields().containsKey("sku2"));
assertNull("'sku*' should not be (or match) a dynamic field", schema.getDynamicPattern("sku*"));
assertTrue("schema should contain dynamic field '*_s'", schema.getDynamicPattern("*_s").equals("*_s"));
final String subsetPattern = "*_dest_sub_s";
final String dynamicPattern1 = schema.getDynamicPattern(subsetPattern);
assertTrue("'" + subsetPattern + "' should match dynamic field '*_s', but instead matches '" + dynamicPattern1 + "'", dynamicPattern1.equals("*_s"));
final String dest_sub_no_ast_s = "dest_sub_no_ast_s";
// Should not be an explicit field
assertFalse(schema.getFields().containsKey(dest_sub_no_ast_s));
final String dynamicPattern2 = schema.getDynamicPattern(dest_sub_no_ast_s);
assertTrue("'" + dest_sub_no_ast_s + "' should match dynamic field '*_s', but instead matches '" + dynamicPattern2 + "'", dynamicPattern2.equals("*_s"));
assertU(adoc("id", "5", "sku1", "10-1839ACX-93", "sku2", "AAM46"));
assertU(commit());
Map<String, String> args = new HashMap<>();
args.put(CommonParams.Q, "text:AAM46");
args.put("indent", "true");
SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
assertQ("sku2 copied to text", req, "//*[@numFound='1']", "//result/doc[1]/int[@name='id'][.='5']");
args = new HashMap<>();
args.put(CommonParams.Q, "1_s:10-1839ACX-93");
args.put("indent", "true");
req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
assertQ("sku1 copied to dynamic dest *_s", req, "//*[@numFound='1']", "//result/doc[1]/int[@name='id'][.='5']", "//result/doc[1]/arr[@name='sku1']/str[.='10-1839ACX-93']");
args = new HashMap<>();
args.put(CommonParams.Q, "1_dest_sub_s:10-1839ACX-93");
args.put("indent", "true");
req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
assertQ("sku1 copied to *_dest_sub_s (*_s subset pattern)", req, "//*[@numFound='1']");
args = new HashMap<>();
args.put(CommonParams.Q, "dest_sub_no_ast_s:AAM46");
args.put("indent", "true");
req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
assertQ("sku2 copied to dest_sub_no_ast_s (*_s subset pattern no asterisk)", req, "//*[@numFound='1']");
}
use of org.apache.solr.common.params.MapSolrParams in project lucene-solr by apache.
the class IndexSchemaTest method testDynamicCopy.
/**
* This test assumes the schema includes:
* <dynamicField name="dynamic_*" type="string" indexed="true" stored="true"/>
* <dynamicField name="*_dynamic" type="string" indexed="true" stored="true"/>
*/
@Test
public void testDynamicCopy() {
SolrCore core = h.getCore();
assertU(adoc("id", "10", "title", "test", "aaa_dynamic", "aaa"));
assertU(commit());
Map<String, String> args = new HashMap<>();
args.put(CommonParams.Q, "title:test");
args.put("indent", "true");
SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
assertQ("Make sure they got in", req, "//*[@numFound='1']", "//result/doc[1]/int[@name='id'][.='10']");
args = new HashMap<>();
args.put(CommonParams.Q, "aaa_dynamic:aaa");
args.put("indent", "true");
req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
assertQ("dynamic source", req, "//*[@numFound='1']", "//result/doc[1]/int[@name='id'][.='10']");
args = new HashMap<>();
args.put(CommonParams.Q, "dynamic_aaa:aaa");
args.put("indent", "true");
req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
assertQ("dynamic destination", req, "//*[@numFound='1']", "//result/doc[1]/int[@name='id'][.='10']");
clearIndex();
}
Aggregations