当前位置: 首页>>代码示例>>Java>>正文


Java ContentStreamBase类代码示例

本文整理汇总了Java中org.apache.solr.common.util.ContentStreamBase的典型用法代码示例。如果您正苦于以下问题:Java ContentStreamBase类的具体用法?Java ContentStreamBase怎么用?Java ContentStreamBase使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ContentStreamBase类属于org.apache.solr.common.util包,在下文中一共展示了ContentStreamBase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setProperties

import org.apache.solr.common.util.ContentStreamBase; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:24,代码来源:SolrDao.java

示例2: unsetProperties

import org.apache.solr.common.util.ContentStreamBase; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:23,代码来源:SolrDao.java

示例3: testAddCustomJsonWithContentStreamUpdateRequest

import org.apache.solr.common.util.ContentStreamBase; //导入依赖的package包/类
@Test
public void testAddCustomJsonWithContentStreamUpdateRequest() throws IOException {
    ContentStreamUpdateRequest request = new ContentStreamUpdateRequest(
            "/update/json/docs");
    request.setParam("json.command", "false");
    request.setParam("split", "/exams");
    request.getParams().add("f", "first:/first");
    request.getParams().add("f", "last:/last");
    request.getParams().add("f", "grade:/grade");
    request.getParams().add("f", "subject:/exams/subject");
    request.getParams().add("f", "test:/exams/test");
    request.getParams().add("f", "marks:/exams/marks");

    request.addContentStream(new ContentStreamBase.StringStream(EXAMPLE_JSON));

    runUpdateRequestTest(request, EXPECTED_SOLR_DOCS);
}
 
开发者ID:bbende,项目名称:solrj-custom-json-update,代码行数:18,代码来源:IndexJSONTest.java

示例4: testAddMultipleContentStreamsWithContentStreamUpdateRequest

import org.apache.solr.common.util.ContentStreamBase; //导入依赖的package包/类
@Test
public void testAddMultipleContentStreamsWithContentStreamUpdateRequest() throws IOException {
    ContentStreamUpdateRequest request = new ContentStreamUpdateRequest(
            "/update/json/docs");
    request.setParam("json.command", "false");
    request.setParam("split", "/exams");
    request.getParams().add("f", "first:/first");
    request.getParams().add("f", "last:/last");
    request.getParams().add("f", "grade:/grade");
    request.getParams().add("f", "subject:/exams/subject");
    request.getParams().add("f", "test:/exams/test");
    request.getParams().add("f", "marks:/exams/marks");

    // add two streams...
    request.addContentStream(new ContentStreamBase.StringStream(EXAMPLE_JSON));
    request.addContentStream(new ContentStreamBase.StringStream(EXAMPLE_JSON2));

    // ensure docs from both streams were added
    Collection<SolrDocument> solrDocuments = new ArrayList<>();
    solrDocuments.addAll(EXPECTED_SOLR_DOCS);
    solrDocuments.addAll(EXPECTED_SOLR_DOCS2);

    runUpdateRequestTest(request, solrDocuments);
}
 
开发者ID:bbende,项目名称:solrj-custom-json-update,代码行数:25,代码来源:IndexJSONTest.java

示例5: testAddMultipleJsonDocsWithContentStreamUpdateRequest

import org.apache.solr.common.util.ContentStreamBase; //导入依赖的package包/类
@Test
public void testAddMultipleJsonDocsWithContentStreamUpdateRequest() throws IOException {
    ContentStreamUpdateRequest request = new ContentStreamUpdateRequest(
            "/update/json/docs");
    request.setParam("json.command", "false");
    request.setParam("split", "/exams");
    request.getParams().add("f", "first:/first");
    request.getParams().add("f", "last:/last");
    request.getParams().add("f", "grade:/grade");
    request.getParams().add("f", "subject:/exams/subject");
    request.getParams().add("f", "test:/exams/test");
    request.getParams().add("f", "marks:/exams/marks");

    // add one stream with two documents...
    final String jsonWithTwoDocs = "[" + EXAMPLE_JSON + "," + EXAMPLE_JSON2 + "]";
    //final String jsonWithTwoDocs = EXAMPLE_JSON + EXAMPLE_JSON2;
    request.addContentStream(new ContentStreamBase.StringStream(jsonWithTwoDocs));

    // ensure both docs were added
    Collection<SolrDocument> solrDocuments = new ArrayList<>();
    solrDocuments.addAll(EXPECTED_SOLR_DOCS);
    solrDocuments.addAll(EXPECTED_SOLR_DOCS2);

    runUpdateRequestTest(request, solrDocuments);
}
 
开发者ID:bbende,项目名称:solrj-custom-json-update,代码行数:26,代码来源:IndexJSONTest.java

示例6: testAddMultipleFlatJsonDocsSplitTopLevel

import org.apache.solr.common.util.ContentStreamBase; //导入依赖的package包/类
@Test
public void testAddMultipleFlatJsonDocsSplitTopLevel()
        throws IOException, SolrServerException {

    ContentStreamUpdateRequest request = new ContentStreamUpdateRequest(
            "/update/json/docs");
    request.setParam("json.command", "false");
    request.setParam("split", "/");

    request.addContentStream(new ContentStreamBase.StringStream(JSON_FLAT));

    // should get two documents added
    QueryResponse qResponse = getQueryResponse(request);
    Assert.assertEquals(2, qResponse.getResults().getNumFound());

    for (SolrDocument solrDocument : qResponse.getResults()) {
        System.out.println(solrDocument);

        // each document should have field1 and field2, plus required fields of id and _version_
        Assert.assertEquals(4, solrDocument.getFieldNames().size());
        Assert.assertTrue(solrDocument.containsKey("id"));
        Assert.assertTrue(solrDocument.containsKey("_version_"));
        Assert.assertTrue(solrDocument.containsKey("field1"));
        Assert.assertTrue(solrDocument.containsKey("field2"));
    }
}
 
开发者ID:bbende,项目名称:solrj-custom-json-update,代码行数:27,代码来源:IndexJSONSchemalessTest.java

示例7: testCommitWithin

import org.apache.solr.common.util.ContentStreamBase; //导入依赖的package包/类
@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();
}
 
开发者ID:europeana,项目名称:search,代码行数:21,代码来源:ExtractingRequestHandlerTest.java

示例8: addDoc

import org.apache.solr.common.util.ContentStreamBase; //导入依赖的package包/类
static void addDoc(String doc, String chain) throws Exception {
  Map<String, String[]> params = new HashMap<>();
  MultiMapSolrParams mmparams = new MultiMapSolrParams(params);
  params.put(UpdateParams.UPDATE_CHAIN, new String[] { chain });
  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();
}
 
开发者ID:europeana,项目名称:search,代码行数:17,代码来源:SignatureUpdateProcessorFactoryTest.java

示例9: addDoc

import org.apache.solr.common.util.ContentStreamBase; //导入依赖的package包/类
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();
}
 
开发者ID:europeana,项目名称:search,代码行数:17,代码来源:UniqFieldsUpdateProcessorFactoryTest.java

示例10: testCommitWithin

import org.apache.solr.common.util.ContentStreamBase; //导入依赖的package包/类
@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();
}
 
开发者ID:europeana,项目名称:search,代码行数:17,代码来源:CSVRequestHandlerTest.java

示例11: testRequestParams

import org.apache.solr.common.util.ContentStreamBase; //导入依赖的package包/类
@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();
}
 
开发者ID:europeana,项目名称:search,代码行数:24,代码来源:XmlUpdateRequestHandlerTest.java

示例12: testExternalEntities

import org.apache.solr.common.util.ContentStreamBase; //导入依赖的package包/类
@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();
}
 
开发者ID:europeana,项目名称:search,代码行数:26,代码来源:XmlUpdateRequestHandlerTest.java

示例13: checkFieldValueOrdering

import org.apache.solr.common.util.ContentStreamBase; //导入依赖的package包/类
private void checkFieldValueOrdering(String rawJson, float fBoost) 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"));
  assertEquals(new Object[] {45L, 67L, 89L} , d.getFieldValues("f").toArray());
  assertEquals(0.0F, fBoost, d.getField("f").getBoost());

  d = p.addCommands.get(1).solrDoc;
  assertEquals(1, d.getFieldNames().size());
  assertEquals("2", d.getFieldValue("id"));

  req.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:21,代码来源:JsonLoaderTest.java

示例14: testExtendedFieldValues

import org.apache.solr.common.util.ContentStreamBase; //导入依赖的package包/类
public void testExtendedFieldValues() 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);
  SolrInputDocument d = add.solrDoc;

  SolrInputField f = d.getField( "id" );
  assertEquals("1", f.getValue());

  f = d.getField( "val_s" );
  Map<String,Object> map = (Map<String,Object>)f.getValue();
  assertEquals("foo",map.get("add"));

  req.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:25,代码来源:JsonLoaderTest.java

示例15: testBooleanValuesInAdd

import org.apache.solr.common.util.ContentStreamBase; //导入依赖的package包/类
@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();
}
 
开发者ID:europeana,项目名称:search,代码行数:25,代码来源:JsonLoaderTest.java


注:本文中的org.apache.solr.common.util.ContentStreamBase类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。