Search in sources :

Example 6 with JsonLoader

use of org.apache.solr.handler.loader.JsonLoader in project lucene-solr by apache.

the class JsonLoaderTest method testBigIntegerValuesInAdd.

@Test
public void testBigIntegerValuesInAdd() throws Exception {
    String str = ("{'add':[{'id':'1','bi1':123456789012345678901,'bi2':1098765432109876543210," + "'bi3':[1234567890123456789012,10987654321098765432109]}]}").replace('\'', '"');
    SolrQueryRequest req = req();
    SolrQueryResponse rsp = new SolrQueryResponse();
    BufferingRequestProcessor p = new BufferingRequestProcessor(null);
    JsonLoader loader = new JsonLoader();
    loader.load(req, rsp, new ContentStreamBase.StringStream(str), p);
    assertEquals(1, p.addCommands.size());
    AddUpdateCommand add = p.addCommands.get(0);
    SolrInputDocument d = add.solrDoc;
    SolrInputField f = d.getField("bi1");
    assertTrue(f.getValue() instanceof String);
    assertEquals("123456789012345678901", f.getValue());
    f = d.getField("bi2");
    assertTrue(f.getValue() instanceof String);
    assertEquals("1098765432109876543210", f.getValue());
    f = d.getField("bi3");
    assertEquals(2, ((List) f.getValue()).size());
    assertTrue(((List) f.getValue()).contains("1234567890123456789012"));
    assertTrue(((List) f.getValue()).contains("10987654321098765432109"));
    req.close();
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrInputDocument(org.apache.solr.common.SolrInputDocument) BufferingRequestProcessor(org.apache.solr.update.processor.BufferingRequestProcessor) SolrInputField(org.apache.solr.common.SolrInputField) JsonLoader(org.apache.solr.handler.loader.JsonLoader) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) ContentStreamBase(org.apache.solr.common.util.ContentStreamBase) Test(org.junit.Test)

Example 7 with JsonLoader

use of org.apache.solr.handler.loader.JsonLoader in project lucene-solr by apache.

the class JsonLoaderTest method testDecimalValuesInAdd.

@Test
public void testDecimalValuesInAdd() throws Exception {
    String str = "{'add':[{'id':'1','d1':256.78,'d2':-5123456789.0,'d3':0.0,'d3':1.0,'d4':1.7E-10}]}".replace('\'', '"');
    SolrQueryRequest req = req();
    SolrQueryResponse rsp = new SolrQueryResponse();
    BufferingRequestProcessor p = new BufferingRequestProcessor(null);
    JsonLoader loader = new JsonLoader();
    loader.load(req, rsp, new ContentStreamBase.StringStream(str), p);
    assertEquals(1, p.addCommands.size());
    AddUpdateCommand add = p.addCommands.get(0);
    SolrInputDocument d = add.solrDoc;
    SolrInputField f = d.getField("d1");
    assertEquals(256.78, f.getValue());
    f = d.getField("d2");
    assertEquals(-5123456789.0, f.getValue());
    f = d.getField("d3");
    assertEquals(2, ((List) f.getValue()).size());
    assertTrue(((List) f.getValue()).contains(0.0));
    assertTrue(((List) f.getValue()).contains(1.0));
    f = d.getField("d4");
    assertEquals(1.7E-10, f.getValue());
    req.close();
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrInputDocument(org.apache.solr.common.SolrInputDocument) BufferingRequestProcessor(org.apache.solr.update.processor.BufferingRequestProcessor) SolrInputField(org.apache.solr.common.SolrInputField) JsonLoader(org.apache.solr.handler.loader.JsonLoader) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) ContentStreamBase(org.apache.solr.common.util.ContentStreamBase) Test(org.junit.Test)

Example 8 with JsonLoader

use of org.apache.solr.handler.loader.JsonLoader in project lucene-solr by apache.

the class JsonLoaderTest method testBooleanValuesInAdd.

@Test
public void testBooleanValuesInAdd() throws Exception {
    String str = "{'add':[{'id':'1','b1':true,'b2':false,'b3':[false,true]}]}".replace('\'', '"');
    SolrQueryRequest req = req();
    SolrQueryResponse rsp = new SolrQueryResponse();
    BufferingRequestProcessor p = new BufferingRequestProcessor(null);
    JsonLoader loader = new JsonLoader();
    loader.load(req, rsp, new ContentStreamBase.StringStream(str), p);
    assertEquals(1, p.addCommands.size());
    AddUpdateCommand add = p.addCommands.get(0);
    SolrInputDocument d = add.solrDoc;
    SolrInputField f = d.getField("b1");
    assertEquals(Boolean.TRUE, f.getValue());
    f = d.getField("b2");
    assertEquals(Boolean.FALSE, f.getValue());
    f = d.getField("b3");
    assertEquals(2, ((List) f.getValue()).size());
    assertEquals(Boolean.FALSE, ((List) f.getValue()).get(0));
    assertEquals(Boolean.TRUE, ((List) f.getValue()).get(1));
    req.close();
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrInputDocument(org.apache.solr.common.SolrInputDocument) BufferingRequestProcessor(org.apache.solr.update.processor.BufferingRequestProcessor) SolrInputField(org.apache.solr.common.SolrInputField) JsonLoader(org.apache.solr.handler.loader.JsonLoader) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) ContentStreamBase(org.apache.solr.common.util.ContentStreamBase) Test(org.junit.Test)

Example 9 with JsonLoader

use of org.apache.solr.handler.loader.JsonLoader in project lucene-solr by apache.

the class JsonLoaderTest method checkTwoChildDocs.

private void checkTwoChildDocs(String rawJsonStr) throws Exception {
    SolrQueryRequest req = req("commit", "true");
    SolrQueryResponse rsp = new SolrQueryResponse();
    BufferingRequestProcessor p = new BufferingRequestProcessor(null);
    JsonLoader loader = new JsonLoader();
    loader.load(req, rsp, new ContentStreamBase.StringStream(rawJsonStr), p);
    assertEquals(1, p.addCommands.size());
    AddUpdateCommand add = p.addCommands.get(0);
    SolrInputDocument d = add.solrDoc;
    SolrInputField f = d.getField("id");
    assertEquals("1", f.getValue());
    SolrInputDocument cd = d.getChildDocuments().get(0);
    SolrInputField cf = cd.getField("id");
    assertEquals("2", cf.getValue());
    cd = d.getChildDocuments().get(1);
    cf = cd.getField("id");
    assertEquals("3", cf.getValue());
    cf = cd.getField("foo_i");
    assertEquals(2, cf.getValueCount());
    assertEquals(new Object[] { 666L, 777L }, cf.getValues().toArray());
    req.close();
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrInputDocument(org.apache.solr.common.SolrInputDocument) BufferingRequestProcessor(org.apache.solr.update.processor.BufferingRequestProcessor) SolrInputField(org.apache.solr.common.SolrInputField) JsonLoader(org.apache.solr.handler.loader.JsonLoader) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) ContentStreamBase(org.apache.solr.common.util.ContentStreamBase)

Example 10 with JsonLoader

use of org.apache.solr.handler.loader.JsonLoader in project lucene-solr by apache.

the class JsonLoaderTest method testSimpleFormatInAdd.

public void testSimpleFormatInAdd() throws Exception {
    String str = "{'add':[{'id':'1'},{'id':'2'}]}".replace('\'', '"');
    SolrQueryRequest req = req();
    SolrQueryResponse rsp = new SolrQueryResponse();
    BufferingRequestProcessor p = new BufferingRequestProcessor(null);
    JsonLoader loader = new JsonLoader();
    loader.load(req, rsp, new ContentStreamBase.StringStream(str), p);
    assertEquals(2, p.addCommands.size());
    AddUpdateCommand add = p.addCommands.get(0);
    SolrInputDocument d = add.solrDoc;
    SolrInputField f = d.getField("id");
    assertEquals("1", f.getValue());
    assertEquals(add.commitWithin, -1);
    assertEquals(add.overwrite, true);
    add = p.addCommands.get(1);
    d = add.solrDoc;
    f = d.getField("id");
    assertEquals("2", f.getValue());
    assertEquals(add.commitWithin, -1);
    assertEquals(add.overwrite, true);
    req.close();
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrInputDocument(org.apache.solr.common.SolrInputDocument) BufferingRequestProcessor(org.apache.solr.update.processor.BufferingRequestProcessor) SolrInputField(org.apache.solr.common.SolrInputField) JsonLoader(org.apache.solr.handler.loader.JsonLoader) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) ContentStreamBase(org.apache.solr.common.util.ContentStreamBase)

Aggregations

JsonLoader (org.apache.solr.handler.loader.JsonLoader)19 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)17 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)17 BufferingRequestProcessor (org.apache.solr.update.processor.BufferingRequestProcessor)17 ContentStreamBase (org.apache.solr.common.util.ContentStreamBase)16 SolrInputDocument (org.apache.solr.common.SolrInputDocument)15 AddUpdateCommand (org.apache.solr.update.AddUpdateCommand)12 SolrInputField (org.apache.solr.common.SolrInputField)11 Test (org.junit.Test)9 Map (java.util.Map)2 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)2 CSVLoader (org.apache.solr.handler.loader.CSVLoader)2 JavabinLoader (org.apache.solr.handler.loader.JavabinLoader)2 XMLLoader (org.apache.solr.handler.loader.XMLLoader)2 DeleteUpdateCommand (org.apache.solr.update.DeleteUpdateCommand)2 HashMap (java.util.HashMap)1 UnaryOperator (java.util.function.UnaryOperator)1 SolrException (org.apache.solr.common.SolrException)1 MapSolrParams (org.apache.solr.common.params.MapSolrParams)1 SolrParams (org.apache.solr.common.params.SolrParams)1