Search in sources :

Example 41 with MapSolrParams

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']");
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) HashMap(java.util.HashMap) SolrCore(org.apache.solr.core.SolrCore) ArrayList(java.util.ArrayList) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) ContentStream(org.apache.solr.common.util.ContentStream) MapSolrParams(org.apache.solr.common.params.MapSolrParams) StringWriter(java.io.StringWriter) QueryResponseWriter(org.apache.solr.response.QueryResponseWriter) ContentStreamBase(org.apache.solr.common.util.ContentStreamBase) Test(org.junit.Test)

Example 42 with MapSolrParams

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']");
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) MapSolrParams(org.apache.solr.common.params.MapSolrParams) HashMap(java.util.HashMap) SolrCore(org.apache.solr.core.SolrCore) Test(org.junit.Test)

Example 43 with MapSolrParams

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']");
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) MapSolrParams(org.apache.solr.common.params.MapSolrParams) HashMap(java.util.HashMap) SolrCore(org.apache.solr.core.SolrCore) Test(org.junit.Test)

Example 44 with MapSolrParams

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']");
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) MapSolrParams(org.apache.solr.common.params.MapSolrParams) HashMap(java.util.HashMap) SolrCore(org.apache.solr.core.SolrCore) Test(org.junit.Test)

Example 45 with MapSolrParams

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:
   * &lt;dynamicField name="dynamic_*" type="string" indexed="true" stored="true"/&gt;
   * &lt;dynamicField name="*_dynamic" type="string" indexed="true" stored="true"/&gt;
   */
@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();
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) MapSolrParams(org.apache.solr.common.params.MapSolrParams) HashMap(java.util.HashMap) SolrCore(org.apache.solr.core.SolrCore) Test(org.junit.Test)

Aggregations

MapSolrParams (org.apache.solr.common.params.MapSolrParams)50 HashMap (java.util.HashMap)33 SolrCore (org.apache.solr.core.SolrCore)24 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)20 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)19 SolrParams (org.apache.solr.common.params.SolrParams)14 Test (org.junit.Test)14 LinkedHashMap (java.util.LinkedHashMap)11 ArrayList (java.util.ArrayList)10 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)10 SolrException (org.apache.solr.common.SolrException)6 UpdateRequestHandler (org.apache.solr.handler.UpdateRequestHandler)6 SolrQueryRequestBase (org.apache.solr.request.SolrQueryRequestBase)6 Map (java.util.Map)4 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)4 Utils.makeMap (org.apache.solr.common.util.Utils.makeMap)4 IOException (java.io.IOException)3 SchemaField (org.apache.solr.schema.SchemaField)3 StringWriter (java.io.StringWriter)2 Collections.singletonMap (java.util.Collections.singletonMap)2