本文整理汇总了Java中org.apache.solr.client.solrj.request.ContentStreamUpdateRequest类的典型用法代码示例。如果您正苦于以下问题:Java ContentStreamUpdateRequest类的具体用法?Java ContentStreamUpdateRequest怎么用?Java ContentStreamUpdateRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ContentStreamUpdateRequest类属于org.apache.solr.client.solrj.request包,在下文中一共展示了ContentStreamUpdateRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testContentStreamRequest
import org.apache.solr.client.solrj.request.ContentStreamUpdateRequest; //导入依赖的package包/类
@Test
public void testContentStreamRequest() throws Exception {
SolrServer server = getSolrServer();
server.deleteByQuery( "*:*" );// delete everything!
server.commit();
QueryResponse rsp = server.query( new SolrQuery( "*:*") );
Assert.assertEquals( 0, rsp.getResults().getNumFound() );
ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update");
up.addFile(getFile("solrj/books.csv"), "application/csv");
up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
NamedList<Object> result = server.request(up);
assertNotNull("Couldn't upload books.csv", result);
rsp = server.query( new SolrQuery( "*:*") );
Assert.assertEquals( 10, rsp.getResults().getNumFound() );
}
示例2: testCollectPing
import org.apache.solr.client.solrj.request.ContentStreamUpdateRequest; //导入依赖的package包/类
@Test
public void testCollectPing() throws Exception {
String configFile = "conf/config.yml";
CloudSolrClient cloudSolrClient = cluster.getSolrClient();
SolrCollectorConfig collectorConfig = new Yaml().loadAs(new FileReader(configFile), SolrCollectorConfig.class);
SolrCollector collector = new SolrCollector(cloudSolrClient, collectorConfig, 1);
collector.register(registry);
// index sample docs
File exampleDocsDir = new File("src/test/files/solr/example/exampledocs");
List<File> xmlFiles = Arrays.asList(exampleDocsDir.listFiles((dir, name) -> name.endsWith(".xml")));
for (File xml : xmlFiles) {
ContentStreamUpdateRequest req = new ContentStreamUpdateRequest("/update");
req.addFile(xml, "application/xml");
cloudSolrClient.request(req, "collection1");
}
cloudSolrClient.commit("collection1");
collector.collect();
assertNotEquals(0.0, registry.getSampleValue("solr_scrape_duration_seconds"));
}
示例3: testMultiContentStreamRequest
import org.apache.solr.client.solrj.request.ContentStreamUpdateRequest; //导入依赖的package包/类
@Test
public void testMultiContentStreamRequest() throws Exception {
SolrServer server = getSolrServer();
server.deleteByQuery( "*:*" );// delete everything!
server.commit();
QueryResponse rsp = server.query( new SolrQuery( "*:*") );
Assert.assertEquals( 0, rsp.getResults().getNumFound() );
ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update");
up.addFile(getFile("solrj/docs1.xml"),"application/xml"); // 2
up.addFile(getFile("solrj/docs2.xml"),"application/xml"); // 3
up.setParam("a", "\u1234");
up.setParam(CommonParams.HEADER_ECHO_PARAMS, CommonParams.EchoParamStyle.ALL.toString());
up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
NamedList<Object> result = server.request(up);
Assert.assertEquals("\u1234",
((NamedList)((NamedList) result.get("responseHeader")).get("params")).get("a"));
assertNotNull("Couldn't upload xml files", result);
rsp = server.query( new SolrQuery( "*:*") );
Assert.assertEquals( 5 , rsp.getResults().getNumFound() );
}
示例4: testNumberOfCommitsWithCommitAfterAdd
import org.apache.solr.client.solrj.request.ContentStreamUpdateRequest; //导入依赖的package包/类
private void testNumberOfCommitsWithCommitAfterAdd()
throws SolrServerException, IOException {
log.info("### STARTING testNumberOfCommitsWithCommitAfterAdd");
long startCommits = getNumCommits((HttpSolrServer) clients.get(0));
ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update");
up.addFile(getFile("books_numeric_ids.csv"), "application/csv");
up.setCommitWithin(900000);
up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
NamedList<Object> result = clients.get(0).request(up);
long endCommits = getNumCommits((HttpSolrServer) clients.get(0));
assertEquals(startCommits + 1L, endCommits);
}
示例5: index
import org.apache.solr.client.solrj.request.ContentStreamUpdateRequest; //导入依赖的package包/类
@Override
public void index() throws SolrServerException, IOException {
String solrID = file.toUri().toString();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Solr: indexing file \"{}\"", file);
}
/* create the update request object */
ContentStreamUpdateRequest updateRequest = new ContentStreamUpdateRequest(EXTRACT_PATH);
updateRequest.addContentStream(getStream());
/* set the additional parameters */
updateRequest.setParams(getSolrParams(file, attrs));
updateRequest.setCommitWithin(getCommitWithin());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Solr: sending binary data ({} ({}), size is {}) to solr server.", file, solrID,
MCRUtils.getSizeFormatted(attrs.size()));
}
long t = System.currentTimeMillis();
/* actually send the request */
getSolrClient().request(updateRequest);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Solr: sending binary data \"{} ({})\" done in {}ms", file, solrID,
System.currentTimeMillis() - t);
}
}
示例6: index
import org.apache.solr.client.solrj.request.ContentStreamUpdateRequest; //导入依赖的package包/类
public void index() throws IOException, SolrServerException {
long tStart = System.currentTimeMillis();
ContentStreamUpdateRequest updateRequest = new ContentStreamUpdateRequest(UPDATE_PATH);
updateRequest.addContentStream(getStream());
if (STYLESHEET.length() > 0) {
updateRequest.setParam("tr", STYLESHEET);
}
updateRequest.setCommitWithin(getCommitWithin());
NamedList<Object> request = getSolrClient().request(updateRequest);
if (LOGGER.isDebugEnabled()) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("Solr: indexing data of \"");
stringBuilder.append(this);
stringBuilder.append("\" (");
stringBuilder.append((System.currentTimeMillis() - tStart));
stringBuilder.append("ms)");
for (Map.Entry<String, Object> entry : request) {
stringBuilder.append('\n');
stringBuilder.append(entry.getKey());
stringBuilder.append('=');
stringBuilder.append(entry.getValue());
}
LOGGER.debug(stringBuilder.toString());
}
}
示例7: testAddCustomJsonWithContentStreamUpdateRequest
import org.apache.solr.client.solrj.request.ContentStreamUpdateRequest; //导入依赖的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);
}
示例8: testAddMultipleContentStreamsWithContentStreamUpdateRequest
import org.apache.solr.client.solrj.request.ContentStreamUpdateRequest; //导入依赖的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);
}
示例9: testAddMultipleJsonDocsWithContentStreamUpdateRequest
import org.apache.solr.client.solrj.request.ContentStreamUpdateRequest; //导入依赖的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);
}
示例10: testAddMultipleFlatJsonDocsSplitTopLevel
import org.apache.solr.client.solrj.request.ContentStreamUpdateRequest; //导入依赖的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"));
}
}
示例11: addDoc
import org.apache.solr.client.solrj.request.ContentStreamUpdateRequest; //导入依赖的package包/类
@Override
public void addDoc(final SSDBNoSQLAddDocPar par) throws SSErr {
// according to Solr specification by adding a document with an ID already
// existing in the index will replace the document (eg. refer to
// http://stackoverflow.com/questions/8494923/solr-block-updating-of-existing-document or
// http://lucene.apache.org/solr/api-4_0_0-ALPHA/doc-files/tutorial.html )
try{
final ContentStreamUpdateRequest csur = new ContentStreamUpdateRequest("/update/extract");
final NamedList<Object> response;
csur.addContentStream(new ContentStreamBase.FileStream(new File(SSConf.getLocalWorkPath() + par.id)));
csur.setParam ("literal.id", par.id);
// csur.setParam ("stream.type", "application/octet-stream");
csur.setAction (AbstractUpdateRequest.ACTION.COMMIT, true, true);
response = solrServer.request(csur);
SSLogU.info("document w/ id " + par.id + " added successfully. ");
}catch(Exception error){
SSServErrReg.regErrThrow(error);
}
}
示例12: testAddMultipleJsonDocsWithNestingSplitTopLevel
import org.apache.solr.client.solrj.request.ContentStreamUpdateRequest; //导入依赖的package包/类
@Test
public void testAddMultipleJsonDocsWithNestingSplitTopLevel()
throws IOException, SolrServerException {
ContentStreamUpdateRequest request = new ContentStreamUpdateRequest(
"/update/json/docs");
request.setParam("json.command", "false");
request.setParam("split", "/");
request.addContentStream(new ContentStreamBase.StringStream(JSON_NESTING));
// should get 2 documents back because we split on /
QueryResponse qResponse = getQueryResponse(request);
Assert.assertEquals(2, qResponse.getResults().getNumFound());
for (SolrDocument solrDocument : qResponse.getResults()) {
System.out.println(solrDocument);
// each document should have field1, field2.nested_field1, and field2.nested_field2
// plus required fields of id and _version_
Assert.assertEquals(5, solrDocument.getFieldNames().size());
Assert.assertTrue(solrDocument.containsKey("id"));
Assert.assertTrue(solrDocument.containsKey("_version_"));
Assert.assertTrue(solrDocument.containsKey("field1"));
Assert.assertTrue(solrDocument.containsKey("field2.nested_field1"));
Assert.assertTrue(solrDocument.containsKey("field2.nested_field2"));
// field2.nested_field1 should have 2 values since we split at the top-level
Assert.assertEquals(2, solrDocument.getFieldValues("field2.nested_field1").size());
// field2.nested_field2 should have 2 values since we split at the top-level
Assert.assertEquals(2, solrDocument.getFieldValues("field2.nested_field2").size());
}
}
示例13: testAddMultipleJsonDocsWithNestingSplitOnNestedDocs
import org.apache.solr.client.solrj.request.ContentStreamUpdateRequest; //导入依赖的package包/类
@Test
public void testAddMultipleJsonDocsWithNestingSplitOnNestedDocs()
throws IOException, SolrServerException {
ContentStreamUpdateRequest request = new ContentStreamUpdateRequest(
"/update/json/docs");
request.setParam("json.command", "false");
request.setParam("split", "/field2");
request.addContentStream(new ContentStreamBase.StringStream(JSON_NESTING));
// should get 4 documents back because we split on field2
QueryResponse qResponse = getQueryResponse(request);
Assert.assertEquals(4, qResponse.getResults().getNumFound());
for (SolrDocument solrDocument : qResponse.getResults()) {
System.out.println(solrDocument);
// each document should have field1, field2.nested_field1, and field2.nested_field2
// plus required fields of id and _version_
Assert.assertEquals(5, solrDocument.getFieldNames().size());
Assert.assertTrue(solrDocument.containsKey("id"));
Assert.assertTrue(solrDocument.containsKey("_version_"));
Assert.assertTrue(solrDocument.containsKey("field1"));
Assert.assertTrue(solrDocument.containsKey("field2.nested_field1"));
Assert.assertTrue(solrDocument.containsKey("field2.nested_field2"));
// field2.nested_field1 should have 1 value since we split on field2
Assert.assertEquals(1, solrDocument.getFieldValues("field2.nested_field1").size());
// field2.nested_field2 should have 1 value since we split on field2
Assert.assertEquals(1, solrDocument.getFieldValues("field2.nested_field2").size());
}
}
示例14: createSolrRequest
import org.apache.solr.client.solrj.request.ContentStreamUpdateRequest; //导入依赖的package包/类
private SolrRequest<UpdateResponse> createSolrRequest(String json) {
final ContentStreamUpdateRequest request = new ContentStreamUpdateRequest(jsonUpdateUrl);
final ContentStream cs = new ContentStreamBase.StringStream(json, CONTENT_TYPE);
request.addContentStream(cs);
LOG.debug("Request generated with JSON: {}", json);
return request;
}
示例15: add
import org.apache.solr.client.solrj.request.ContentStreamUpdateRequest; //导入依赖的package包/类
@Override
public void add(String path, Map<String, Object> data, ResourceBinary binary) throws IndexException {
if (binary == null) {
add(path, data);
return;
}
ContentStreamUpdateRequest request = new ContentStreamUpdateRequest("/update/extract");
request.addContentStream(new AssetContentStream(binary));
request.setParam("literal.id", buildId(path));
Set<String> fields = data.keySet();
for (String field : fields) {
if (field.equals(this.idField)) {
throw new IndexException("ID field must not get populated through data fields.");
}
Object fieldValue = data.get(field);
if (fieldValue != null) {
if (fieldValue instanceof Collection) {
Collection<?> fieldValues = (Collection) fieldValue;
for (Object value : fieldValues) {
// TODO deal with numeric & date type values (format to string)
request.setParam("literal." + field, valueToString(value));
}
} else {
// assume it's one of the supported data types
request.setParam("literal." + field, valueToString(fieldValue));
}
}
}
request.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
try {
solrServer.request(request);
} catch (Exception e) {
throw new IndexException(e);
}
}