org.apache.solr.common.util.ContentStreamBase Java Examples
The following examples show how to use
org.apache.solr.common.util.ContentStreamBase.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XmlUpdateRequestHandlerTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testRequestParams() throws Exception { String xml = "<add>" + " <doc>" + " <field name=\"id\">12345</field>" + " <field name=\"name\">kitten</field>" + " </doc>" + "</add>"; SolrQueryRequest req = req("commitWithin","100","overwrite","false"); SolrQueryResponse rsp = new SolrQueryResponse(); BufferingRequestProcessor p = new BufferingRequestProcessor(null); XMLLoader loader = new XMLLoader().init(null); loader.load(req, rsp, new ContentStreamBase.StringStream(xml), p); AddUpdateCommand add = p.addCommands.get(0); assertEquals(100, add.commitWithin); assertEquals(false, add.overwrite); req.close(); }
Example #2
Source File: TestUtils.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testBinaryCommands() throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (final JavaBinCodec jbc = new JavaBinCodec()) { jbc.marshal((MapWriter) ew -> { ew.put("set-user", fromJSONString("{x:y}")); ew.put("set-user", fromJSONString("{x:y,x1:y1}")); ew.put("single", asList(fromJSONString("[{x:y,x1:y1},{x2:y2}]"), fromJSONString( "{x2:y2}"))); ew.put("multi", asList(fromJSONString("{x:y,x1:y1}"), fromJSONString( "{x2:y2}"))); }, baos); } ContentStream stream = new ContentStreamBase.ByteArrayStream(baos.toByteArray(),null, "application/javabin"); @SuppressWarnings({"rawtypes"}) List<CommandOperation> commands = CommandOperation.readCommands(Collections.singletonList(stream), new NamedList(), Collections.singleton("single")); assertEquals(5, commands.size()); }
Example #3
Source File: TestV1toV2ApiMapper.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test // commented out on: 24-Dec-2018 @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // added 20-Sep-2018 public void testCreate() throws IOException { Create cmd = CollectionAdminRequest .createCollection("mycoll", "conf1", 3, 2) .setProperties(ImmutableMap.<String,String>builder() .put("p1","v1") .put("p2","v2") .build()); V2Request v2r = V1toV2ApiMapper.convert(cmd).build(); Map<?,?> m = (Map<?,?>) Utils.fromJSON(ContentStreamBase.create(new BinaryRequestWriter(), v2r).getStream()); assertEquals("/c", v2r.getPath()); assertEquals("v1", Utils.getObjectByPath(m,true,"/create/properties/p1")); assertEquals("v2", Utils.getObjectByPath(m,true,"/create/properties/p2")); assertEquals("3", Utils.getObjectByPath(m,true,"/create/numShards")); assertEquals("2", Utils.getObjectByPath(m,true,"/create/nrtReplicas")); }
Example #4
Source File: AbstractAlfrescoSolrIT.java From SearchServices with GNU Lesser General Public License v3.0 | 6 votes |
/** * Creates a solr request. * @param params * @param json * @return */ public SolrServletRequest areq(ModifiableSolrParams params, String json) { if(params.get("wt" ) == null) { params.add("wt","xml"); } SolrServletRequest req = new SolrServletRequest(getCore(), null); req.setParams(params); if(json != null) { ContentStream stream = new ContentStreamBase.StringStream(json); ArrayList<ContentStream> streams = new ArrayList<ContentStream>(); streams.add(stream); req.setContentStreams(streams); } return req; }
Example #5
Source File: EmbeddedSolrServerTestBase.java From lucene-solr with Apache License 2.0 | 6 votes |
public Collection<ContentStream> download(final String collection, final String... names) { final Path base = Paths.get(getSolrClient().getCoreContainer().getSolrHome(), collection); final List<ContentStream> result = new ArrayList<>(); if (Files.exists(base)) { for (final String name : names) { final File file = new File(base.toFile(), name); if (file.exists() && file.canRead()) { try { final ByteArrayOutputStream os = new ByteArrayOutputStream(); ByteStreams.copy(new FileInputStream(file), os); final ByteArrayStream stream = new ContentStreamBase.ByteArrayStream(os.toByteArray(), name); result.add(stream); } catch (final IOException e) { throw new RuntimeException(e); } } } } return result; }
Example #6
Source File: SolrTestCaseJ4.java From lucene-solr with Apache License 2.0 | 6 votes |
public static void addDoc(String doc, String updateRequestProcessorChain) throws Exception { Map<String, String[]> params = new HashMap<>(); MultiMapSolrParams mmparams = new MultiMapSolrParams(params); params.put(UpdateParams.UPDATE_CHAIN, new String[]{updateRequestProcessorChain}); SolrQueryRequestBase req = new SolrQueryRequestBase(h.getCore(), (SolrParams) mmparams) { }; UpdateRequestHandler handler = new UpdateRequestHandler(); handler.init(null); ArrayList<ContentStream> streams = new ArrayList<>(2); streams.add(new ContentStreamBase.StringStream(doc)); req.setContentStreams(streams); handler.handleRequestBody(req, new SolrQueryResponse()); req.close(); }
Example #7
Source File: TestRerankBase.java From lucene-solr with Apache License 2.0 | 6 votes |
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()); }
Example #8
Source File: ExtractingRequestHandlerTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testCommitWithin() throws Exception { ExtractingRequestHandler handler = (ExtractingRequestHandler) h.getCore().getRequestHandler("/update/extract"); assertTrue("handler is null and it shouldn't be", handler != null); SolrQueryRequest req = req("literal.id", "one", ExtractingParams.RESOURCE_NAME, "extraction/version_control.txt", "commitWithin", "200" ); SolrQueryResponse rsp = new SolrQueryResponse(); BufferingRequestProcessor p = new BufferingRequestProcessor(null); ExtractingDocumentLoader loader = (ExtractingDocumentLoader) handler.newLoader(req, p); loader.load(req, rsp, new ContentStreamBase.FileStream(getFile("extraction/version_control.txt")),p); AddUpdateCommand add = p.addCommands.get(0); assertEquals(200, add.commitWithin); req.close(); }
Example #9
Source File: JsonLoaderTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@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(); }
Example #10
Source File: Sparql11SearchHandlerTestCase.java From SolRDF with Apache License 2.0 | 6 votes |
@Test public void queryUsingPOSTDirectly() throws Exception { when(httpRequest.getContentType()).thenReturn(WebContent.contentTypeSPARQLQuery); when(httpRequest.getMethod()).thenReturn("POST"); final List<ContentStream> dummyStream = new ArrayList<ContentStream>(1); dummyStream.add(new ContentStreamBase.ByteArrayStream(new byte[0], "dummy") { @Override public String getContentType() { return WebContent.contentTypeSPARQLUpdate; } }); when(request.getContentStreams()).thenReturn(dummyStream); when(request.getParams()).thenReturn(new ModifiableSolrParams()); cut.handleRequestBody(request, response); verify(cut).requestHandler(request, Sparql11SearchHandler.DEFAULT_SEARCH_HANDLER_NAME); }
Example #11
Source File: Sparql11SearchHandlerTestCase.java From SolRDF with Apache License 2.0 | 6 votes |
@Test public void updateUsingPOSTDirectly() throws Exception { when(httpRequest.getContentType()).thenReturn(WebContent.contentTypeSPARQLUpdate); when(httpRequest.getMethod()).thenReturn("POST"); final List<ContentStream> dummyStream = new ArrayList<ContentStream>(1); dummyStream.add(new ContentStreamBase.ByteArrayStream(new byte[0], "dummy") { @Override public String getContentType() { return WebContent.contentTypeSPARQLUpdate; } }); when(request.getContentStreams()).thenReturn(dummyStream); when(request.getParams()).thenReturn(new ModifiableSolrParams()); cut.handleRequestBody(request, response); verify(cut).requestHandler(request, Sparql11SearchHandler.DEFAULT_UPDATE_HANDLER_NAME); }
Example #12
Source File: JsonLoaderTest.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testAtomicUpdateFieldValue() throws Exception { String str = "[{'id':'1', 'val_s':{'add':'foo'}}]".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); assertEquals(add.commitWithin, -1); assertEquals(add.overwrite, true); assertEquals("SolrInputDocument(fields: [id=1, val_s={add=foo}])", add.solrDoc.toString()); req.close(); }
Example #13
Source File: JsonLoaderTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testIntegerValuesInAdd() throws Exception { String str = "{'add':[{'id':'1','i1':256,'i2':-5123456789,'i3':[0,1]}]}".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("i1"); assertEquals(256L, f.getValue()); f = d.getField("i2"); assertEquals(-5123456789L, f.getValue()); f = d.getField("i3"); assertEquals(2, ((List)f.getValue()).size()); assertEquals(0L, ((List)f.getValue()).get(0)); assertEquals(1L, ((List)f.getValue()).get(1)); req.close(); }
Example #14
Source File: XmlUpdateRequestHandlerTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testExternalEntities() throws Exception { String file = getFile("mailing_lists.pdf").toURI().toASCIIString(); String xml = "<?xml version=\"1.0\"?>" + // check that external entities are not resolved! "<!DOCTYPE foo [<!ENTITY bar SYSTEM \""+file+"\">]>" + "<add>" + " &bar;" + " <doc>" + " <field name=\"id\">12345</field>" + " <field name=\"name\">kitten</field>" + " </doc>" + "</add>"; SolrQueryRequest req = req(); SolrQueryResponse rsp = new SolrQueryResponse(); BufferingRequestProcessor p = new BufferingRequestProcessor(null); XMLLoader loader = new XMLLoader().init(null); loader.load(req, rsp, new ContentStreamBase.StringStream(xml), p); AddUpdateCommand add = p.addCommands.get(0); assertEquals("12345", add.solrDoc.getField("id").getFirstValue()); req.close(); }
Example #15
Source File: SolrDao.java From DataHubSystem with GNU Affero General Public License v3.0 | 6 votes |
/** * Unset the given properties that have been previously set with {@link #setProperties(Map)}. * @param props properties to unset. * @throws IOException network error. * @throws SolrServerException solr error. */ public void unsetProperties(Set<String> props) throws SolrServerException, IOException { // Solrj does not support the config API yet. StringBuilder command = new StringBuilder("{\"unset-property\": ["); for (String prop: props) { command.append('"').append(prop).append('"').append(','); } command.setLength(command.length()-1); // remove last comma command.append("]}"); GenericSolrRequest rq = new GenericSolrRequest(SolrRequest.METHOD.POST, "/config", null); ContentStream content = new ContentStreamBase.StringStream(command.toString()); rq.setContentStreams(Collections.singleton(content)); rq.process(solrClient); }
Example #16
Source File: SolrDao.java From DataHubSystem with GNU Affero General Public License v3.0 | 6 votes |
/** * Set the given properties and values using the config API. * @param props properties to set. * @throws IOException network error. * @throws SolrServerException solr error. */ public void setProperties(Map<String, String> props) throws SolrServerException, IOException { // Solrj does not support the config API yet. StringBuilder command = new StringBuilder("{\"set-property\": {"); for (Map.Entry<String, String> entry: props.entrySet()) { command.append('"').append(entry.getKey()).append('"').append(':'); command.append(entry.getValue()).append(','); } command.setLength(command.length()-1); // remove last comma command.append("}}"); GenericSolrRequest rq = new GenericSolrRequest(SolrRequest.METHOD.POST, "/config", null); ContentStream content = new ContentStreamBase.StringStream(command.toString()); rq.setContentStreams(Collections.singleton(content)); rq.process(solrClient); }
Example #17
Source File: CSVRequestHandlerTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testCommitWithin() throws Exception { String csvString = "id;name\n123;hello"; SolrQueryRequest req = req("separator", ";", "commitWithin", "200"); SolrQueryResponse rsp = new SolrQueryResponse(); BufferingRequestProcessor p = new BufferingRequestProcessor(null); CSVLoader loader = new CSVLoader(); loader.load(req, rsp, new ContentStreamBase.StringStream.StringStream(csvString), p); AddUpdateCommand add = p.addCommands.get(0); assertEquals(200, add.commitWithin); req.close(); }
Example #18
Source File: UniqFieldsUpdateProcessorFactoryTest.java From lucene-solr with Apache License 2.0 | 6 votes |
private void addDoc(String doc) throws Exception { Map<String, String[]> params = new HashMap<>(); MultiMapSolrParams mmparams = new MultiMapSolrParams(params); params.put(UpdateParams.UPDATE_CHAIN, new String[] { "uniq-fields" }); SolrQueryRequestBase req = new SolrQueryRequestBase(h.getCore(), (SolrParams) mmparams) { }; UpdateRequestHandler handler = new UpdateRequestHandler(); handler.init(null); ArrayList<ContentStream> streams = new ArrayList<>(2); streams.add(new ContentStreamBase.StringStream(doc)); req.setContentStreams(streams); handler.handleRequestBody(req, new SolrQueryResponse()); req.close(); }
Example #19
Source File: TestSubQueryTransformerDistrib.java From lucene-solr with Apache License 2.0 | 6 votes |
private void addDocs(String collection, List<String> docs) throws SolrServerException, IOException { StringBuilder upd = new StringBuilder("<update>"); upd.append("<delete><query>*:*</query></delete>"); for (Iterator<String> iterator = docs.iterator(); iterator.hasNext();) { String add = iterator.next(); upd.append(add); if (rarely()) { upd.append(commit("softCommit", "true")); } if (rarely() || !iterator.hasNext()) { if (!iterator.hasNext()) { upd.append(commit("softCommit", "false")); } upd.append("</update>"); ContentStreamUpdateRequest req = new ContentStreamUpdateRequest("/update"); req.addContentStream(new ContentStreamBase.StringStream(upd.toString(),"text/xml")); cluster.getSolrClient().request(req, collection); upd.setLength("<update>".length()); } } }
Example #20
Source File: JsonLoaderTest.java From lucene-solr with Apache License 2.0 | 6 votes |
private void checkFieldValueOrdering(String rawJson) throws Exception { SolrQueryRequest req = req(); SolrQueryResponse rsp = new SolrQueryResponse(); BufferingRequestProcessor p = new BufferingRequestProcessor(null); JsonLoader loader = new JsonLoader(); loader.load(req, rsp, new ContentStreamBase.StringStream(rawJson), p); assertEquals( 2, p.addCommands.size() ); SolrInputDocument d = p.addCommands.get(0).solrDoc; assertEquals(2, d.getFieldNames().size()); assertEquals("1", d.getFieldValue("id")); assertArrayEquals(new Object[] {45L, 67L, 89L} , d.getFieldValues("f").toArray()); d = p.addCommands.get(1).solrDoc; assertEquals(1, d.getFieldNames().size()); assertEquals("2", d.getFieldValue("id")); req.close(); }
Example #21
Source File: JsonLoaderTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@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(); }
Example #22
Source File: JsonLoaderTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testBigDecimalValuesInAdd() throws Exception { String str = ("{'add':[{'id':'1','bd1':0.12345678901234567890123456789012345," + "'bd2':12345678901234567890.12345678901234567890,'bd3':0.012345678901234567890123456789012345," + "'bd3':123456789012345678900.012345678901234567890}]}").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("bd1"); assertTrue(f.getValue() instanceof String); assertEquals("0.12345678901234567890123456789012345", f.getValue()); f = d.getField("bd2"); assertTrue(f.getValue() instanceof String); assertEquals("12345678901234567890.12345678901234567890", f.getValue()); f = d.getField("bd3"); assertEquals(2, ((List)f.getValue()).size()); assertTrue(((List)f.getValue()).contains("0.012345678901234567890123456789012345")); assertTrue(((List)f.getValue()).contains("123456789012345678900.012345678901234567890")); req.close(); }
Example #23
Source File: XsltUpdateRequestHandlerTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@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(); try (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']" , "//str[@name='id'][.='12345']" ); }
Example #24
Source File: JsonLoaderTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testSingleRelationalChildDoc() throws Exception { String str = "{\n" + " \"add\": {\n" + " \"doc\": {\n" + " \"id\": \"1\",\n" + " \"child1\": \n" + " {\n" + " \"id\": \"2\",\n" + " \"foo_s\": \"Yaz\"\n" + " },\n" + " }\n" + " }\n" + "}"; 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(str), p); assertEquals( 1, p.addCommands.size() ); AddUpdateCommand add = p.addCommands.get(0); SolrInputDocument one = add.solrDoc; assertEquals("1", one.getFieldValue("id")); assertTrue(one.keySet().contains("child1")); SolrInputDocument two = (SolrInputDocument) one.getField("child1").getValue(); assertEquals("2", two.getFieldValue("id")); assertEquals("Yaz", two.getFieldValue("foo_s")); req.close(); }
Example #25
Source File: XsltUpdateRequestHandlerTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testEntities() throws Exception { // use a binary file, so when it's loaded fail with XML eror: String file = getFile("mailing_lists.pdf").toURI().toASCIIString(); String xml = "<?xml version=\"1.0\"?>" + "<!DOCTYPE foo [" + // check that external entities are not resolved! "<!ENTITY bar SYSTEM \""+file+"\">"+ // but named entities should be "<!ENTITY wacky \"zzz\">"+ "]>" + "<random>" + " &bar;" + " <document>" + " <node name=\"id\" value=\"12345\"/>" + " <node name=\"foo_s\" value=\"&wacky;\"/>" + " </document>" + "</random>"; SolrQueryRequest req = req(CommonParams.TR, "xsl-update-handler-test.xsl"); SolrQueryResponse rsp = new SolrQueryResponse(); BufferingRequestProcessor p = new BufferingRequestProcessor(null); XMLLoader loader = new XMLLoader().init(null); loader.load(req, rsp, new ContentStreamBase.StringStream(xml), p); AddUpdateCommand add = p.addCommands.get(0); assertEquals("12345", add.solrDoc.getField("id").getFirstValue()); assertEquals("zzz", add.solrDoc.getField("foo_s").getFirstValue()); req.close(); }
Example #26
Source File: JsonLoaderTest.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testSimpleFormat() throws Exception { String str = "[{'id':'1'},{'id':'2'}]".replace('\'', '"'); SolrQueryRequest req = req("commitWithin","100", "overwrite","false"); 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, 100); assertFalse(add.overwrite); add = p.addCommands.get(1); d = add.solrDoc; f = d.getField( "id" ); assertEquals("2", f.getValue()); assertEquals(add.commitWithin, 100); assertFalse(add.overwrite); req.close(); }
Example #27
Source File: JsonLoaderTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testInvalidJsonProducesBadRequestSolrException() throws Exception { SolrQueryResponse rsp = new SolrQueryResponse(); BufferingRequestProcessor p = new BufferingRequestProcessor(null); JsonLoader loader = new JsonLoader(); String invalidJsonString = "}{"; SolrException ex = expectThrows(SolrException.class, () -> { loader.load(req(), rsp, new ContentStreamBase.StringStream(invalidJsonString), p); }); assertEquals(SolrException.ErrorCode.BAD_REQUEST.code, ex.code()); assertTrue(ex.getMessage().contains("Cannot parse")); assertTrue(ex.getMessage().contains("JSON")); }
Example #28
Source File: JsonLoaderTest.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testMultipleDocsWithoutArray() throws Exception { String doc = "\n" + "\n" + "{\"f1\": 1111 }\n" + "\n" + "{\"f1\": 2222 }\n"; SolrQueryRequest req = req("srcField","_src_"); req.getContext().put("path","/update/json/docs"); SolrQueryResponse rsp = new SolrQueryResponse(); BufferingRequestProcessor p = new BufferingRequestProcessor(null); JsonLoader loader = new JsonLoader(); loader.load(req, rsp, new ContentStreamBase.StringStream(doc), p); assertEquals( 2, p.addCommands.size() ); }
Example #29
Source File: TestCSVLoader.java From lucene-solr with Apache License 2.0 | 5 votes |
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); }
Example #30
Source File: JsonLoaderTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@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(); }