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


Java UpdateRequest类代码示例

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


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

示例1: indexAndCommitOneDocument

import org.apache.solr.client.solrj.request.UpdateRequest; //导入依赖的package包/类
/**
 * Indexiert das übergebene Dokument und übernimmt die Änderungen in den Solr-Index
 * durch das Ausführen eines Commits.
 *
 * @param gutenbergDoc das zu indexierende Dokument
 */
public void indexAndCommitOneDocument(GutenbergDoc gutenbergDoc) {
    SolrInputDocument document = buildSolrDoc(gutenbergDoc);

    UpdateRequest updateRequest = new UpdateRequest();
    updateRequest.setBasicAuthCredentials(USERNAME, PASSWORD);
    updateRequest.add(document);
    updateRequest.setAction(AbstractUpdateRequest.ACTION.COMMIT, false, false);

    try {
        updateRequest.process(solrClient);
        System.out.println("Dokument " + gutenbergDoc.getDocId() + " erfolgreich indexiert!");
    }
    catch (SolrServerException|IOException e) {
        System.err.println("Fehler bei der Indexierung des Dokuments " + gutenbergDoc.getDocId() + ": " + e.getMessage());
        updateRequest.rollback();
    }
}
 
开发者ID:saschaszott,项目名称:suma-tech,代码行数:24,代码来源:SolrIndexer.java

示例2: indexDocumentsAndCommit

import org.apache.solr.client.solrj.request.UpdateRequest; //导入依赖的package包/类
/**
 * Indexiert die übergebene Liste von Dokumenten und führt am Ende ein Commit durch.
 *
 * Tritt während der Indexierung ein Fehler auf, so werden die Änderungen nicht
 * zurückgenommen, die bereits erfolgreich in den Solr-Index geschrieben werden konnten.
 *
 * @param gutenbergDocs die Liste der zu indexierenden Dokumente
 */
public void indexDocumentsAndCommit(List<GutenbergDoc> gutenbergDocs) {
    UpdateRequest updateRequest = new UpdateRequest();
    updateRequest.setBasicAuthCredentials(USERNAME, PASSWORD);
    for (GutenbergDoc gutenbergDoc : gutenbergDocs) {
        SolrInputDocument solrInputDocument = buildSolrDoc(gutenbergDoc);
        if (gutenbergDoc.getDocId().equals("9")) {
            // füge zu Dokument 9 ein Feld hinzu, dass es nicht im Solr-Schema gibt
            solrInputDocument.addField("foo", "bar");
        }
        updateRequest.add(solrInputDocument);
    }
    updateRequest.setAction(AbstractUpdateRequest.ACTION.COMMIT, false, false);

    try {
        updateRequest.process(solrClient);
        System.out.println(gutenbergDocs.size() + " Dokumente erfolgreich indexiert!");
    }
    catch (SolrServerException|IOException e) {
        System.err.println("Fehler bei der Indexierung der Dokumente: " + e.getMessage());
        updateRequest.rollback();
    }
}
 
开发者ID:saschaszott,项目名称:suma-tech,代码行数:31,代码来源:SolrIndexer.java

示例3: indexAndCommitDocuments

import org.apache.solr.client.solrj.request.UpdateRequest; //导入依赖的package包/类
/**
 * Indexiert die übergebene Liste von Dokumenten und führt nach jedem Dokument einen Commit durch.
 *
 * Tritt während der Indexierung eines Dokuments ein Fehler auf, so gehen die zuvor bereits
 * erfolgreich indexierten Dokumente nicht verloren.
 *
 * @param gutenbergDocs die Liste der zu indexierenden Dokumente
 */
public void indexAndCommitDocuments(List<GutenbergDoc> gutenbergDocs) {
    for (GutenbergDoc gutenbergDoc : gutenbergDocs) {
        UpdateRequest updateRequest = new UpdateRequest();
        updateRequest.setBasicAuthCredentials(USERNAME, PASSWORD);

        SolrInputDocument solrInputDocument = buildSolrDoc(gutenbergDoc);
        if (gutenbergDoc.getDocId().equals("9")) {
            // füge zu Dokument 9 ein Feld hinzu, dass es nicht im Solr-Schema gibt
            solrInputDocument.addField("foo", "bar");
        }
        updateRequest.add(solrInputDocument);
        updateRequest.setAction(AbstractUpdateRequest.ACTION.COMMIT, false, false);

        try {
            updateRequest.process(solrClient);
            System.out.println("Dokument " + gutenbergDoc.getDocId() + " erfolgreich indexiert!");
        }
        catch (SolrServerException|IOException e) {
            System.err.println("Fehler bei der Indexierung der Dokumente: " + e.getMessage());
            updateRequest.rollback();
        }
    }
}
 
开发者ID:saschaszott,项目名称:suma-tech,代码行数:32,代码来源:SolrIndexer.java

示例4: indexAndCommitOneDocument

import org.apache.solr.client.solrj.request.UpdateRequest; //导入依赖的package包/类
/**
 * Indexiert das übergebene Gutenberg-Dokument und übernimmt die Änderungen in den Solr-Index
 * durch das Ausführen eines Commits.
 *
 * @param gutenbergDoc das zu indexierende Dokument
 */
private void indexAndCommitOneDocument(GutenbergDoc gutenbergDoc) {
    SolrInputDocument document = buildSolrDoc(gutenbergDoc);

    UpdateRequest updateRequest = new UpdateRequest();
    updateRequest.setBasicAuthCredentials(Configuration.USERNAME, Configuration.PASSWORD);
    updateRequest.add(document);
    updateRequest.setAction(AbstractUpdateRequest.ACTION.COMMIT, false, false);

    try {
        updateRequest.process(solrClient);
        System.out.println("Dokument " + gutenbergDoc.getDocId() + " erfolgreich indexiert!");
    }
    catch (SolrServerException|IOException e) {
        System.err.println("Fehler bei der Indexierung des Dokuments " + gutenbergDoc.getDocId() + ": " + e.getMessage());
        updateRequest.rollback();
    }
}
 
开发者ID:saschaszott,项目名称:suma-tech,代码行数:24,代码来源:SolrIndexerComplete.java

示例5: deleteIndividualFieldsFromIndex

import org.apache.solr.client.solrj.request.UpdateRequest; //导入依赖的package包/类
private void deleteIndividualFieldsFromIndex(String collectionName, String keyIdField, String docId, HashSet<IndexEntry> fieldDeletions) throws SolrServerException, IOException {
    if (fieldDeletions.isEmpty()) return;

    Map<String, String> fieldDeletes = new HashMap<String, String>(1) {{ put("set", null); }};

    SolrInputDocument doc = new SolrInputDocument();
    doc.addField(keyIdField, docId);
    StringBuilder sb = new StringBuilder();
    for (IndexEntry fieldToDelete : fieldDeletions) {
        doc.addField(fieldToDelete.field, fieldDeletes);
        sb.append(fieldToDelete).append(",");
    }

    if (logger.isTraceEnabled())
        logger.trace("Deleting individual fields [{}] for document {}", sb.toString(), docId);

    UpdateRequest singleDocument = newUpdateRequest();
    singleDocument.add(doc);
    solrClient.request(singleDocument, collectionName);
}
 
开发者ID:graben1437,项目名称:titan1withtp3.1,代码行数:21,代码来源:SolrIndex.java

示例6: close

import org.apache.solr.client.solrj.request.UpdateRequest; //导入依赖的package包/类
public void close() throws IOException {
  try {
    if (!inputDocs.isEmpty()) {
      LOG.info("Indexing " + Integer.toString(inputDocs.size()) + " documents");
      if (numDeletes > 0) {
        LOG.info("Deleting " + Integer.toString(numDeletes) + " documents");
      }
      UpdateRequest req = new UpdateRequest();
      req.add(inputDocs);
      req.setParams(params);
      req.process(solr);
      inputDocs.clear();
    }
    // solr.commit();
  } catch (final SolrServerException e) {
    throw makeIOException(e);
  }
}
 
开发者ID:yahoo,项目名称:anthelion,代码行数:19,代码来源:SolrWriter.java

示例7: getContentStreams

import org.apache.solr.client.solrj.request.UpdateRequest; //导入依赖的package包/类
@Override
public Collection<ContentStream> getContentStreams(SolrRequest req) throws IOException {
  if (req instanceof UpdateRequest) {
    UpdateRequest updateRequest = (UpdateRequest) req;
    if (isNull(updateRequest.getDocuments()) &&
            isNull(updateRequest.getDeleteByIdMap()) &&
            isNull(updateRequest.getDeleteQuery())
            && (updateRequest.getDocIterator() == null) ) {
      return null;
    }
    List<ContentStream> l = new ArrayList<>();
    l.add(new LazyContentStream(updateRequest));
    return l;
  } else {
    return super.getContentStreams(req);
  }

}
 
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:BinaryRequestWriter.java

示例8: addBeans

import org.apache.solr.client.solrj.request.UpdateRequest; //导入依赖的package包/类
/**
 * Adds the beans supplied by the given iterator.
 * 
 * @param beanIterator
 *          the iterator which returns Beans
 * 
 * @return the response from the SolrServer
 */
public UpdateResponse addBeans(final Iterator<?> beanIterator)
    throws SolrServerException, IOException {
  UpdateRequest req = new UpdateRequest();
  req.setDocIterator(new Iterator<SolrInputDocument>() {
    
    @Override
    public boolean hasNext() {
      return beanIterator.hasNext();
    }
    
    @Override
    public SolrInputDocument next() {
      Object o = beanIterator.next();
      if (o == null) return null;
      return getBinder().toSolrInputDocument(o);
    }
    
    @Override
    public void remove() {
      beanIterator.remove();
    }
  });
  return req.process(this);
}
 
开发者ID:europeana,项目名称:search,代码行数:33,代码来源:HttpSolrServer.java

示例9: getMinAchievedReplicationFactor

import org.apache.solr.client.solrj.request.UpdateRequest; //导入依赖的package包/类
/**
 * Useful for determining the minimum achieved replication factor across
 * all shards involved in processing an update request, typically useful
 * for gauging the replication factor of a batch. 
 */
@SuppressWarnings("rawtypes")
public int getMinAchievedReplicationFactor(String collection, NamedList resp) {
  // it's probably already on the top-level header set by condense
  NamedList header = (NamedList)resp.get("responseHeader");
  Integer achRf = (Integer)header.get(UpdateRequest.REPFACT);
  if (achRf != null)
    return achRf.intValue();

  // not on the top-level header, walk the shard route tree
  Map<String,Integer> shardRf = getShardReplicationFactor(collection, resp);
  for (Integer rf : shardRf.values()) {
    if (achRf == null || rf < achRf) {
      achRf = rf;
    }
  }    
  return (achRf != null) ? achRf.intValue() : -1;
}
 
开发者ID:europeana,项目名称:search,代码行数:23,代码来源:CloudSolrServer.java

示例10: testChineseDefaults

import org.apache.solr.client.solrj.request.UpdateRequest; //导入依赖的package包/类
@Test
public void testChineseDefaults() throws Exception {
  SolrServer server = getSolrServer();
  // Empty the database...
  server.deleteByQuery( "*:*" );// delete everything!
  server.commit();
  assertNumFound( "*:*", 0 ); // make sure it got in

  // Beijing medical University
  UpdateRequest req = new UpdateRequest();
  SolrInputDocument doc = new SolrInputDocument();
  doc.addField("id", "42");
  doc.addField("text", "北京医科大学");
  req.add(doc);

  req.setAction(ACTION.COMMIT, true, true );
  req.process( server );

  // Beijing university should match:
  SolrQuery query = new SolrQuery("北京大学");
  QueryResponse rsp = server.query( query );
  assertEquals(1, rsp.getResults().getNumFound());
}
 
开发者ID:europeana,项目名称:search,代码行数:24,代码来源:SolrExampleTests.java

示例11: index_specific

import org.apache.solr.client.solrj.request.UpdateRequest; //导入依赖的package包/类
@Override
protected void index_specific(int serverNumber, Object... fields)
    throws Exception {
  SolrInputDocument doc = new SolrInputDocument();
  for (int i = 0; i < fields.length; i += 2) {
    doc.addField((String) (fields[i]), fields[i + 1]);
  }
  controlClient.add(doc);
  
  HttpSolrServer client = (HttpSolrServer) clients
      .get(serverNumber);
  
  UpdateRequest ureq = new UpdateRequest();
  ureq.add(doc);
  // ureq.setParam("update.chain", DISTRIB_UPDATE_CHAIN);
  ureq.process(client);
}
 
开发者ID:europeana,项目名称:search,代码行数:18,代码来源:AbstractFullDistribZkTestBase.java

示例12: testDistribOpenSearcher

import org.apache.solr.client.solrj.request.UpdateRequest; //导入依赖的package包/类
private void testDistribOpenSearcher() {
  SolrCmdDistributor cmdDistrib = new SolrCmdDistributor(updateShardHandler);
  UpdateRequest updateRequest = new UpdateRequest();

  CommitUpdateCommand ccmd = new CommitUpdateCommand(null, false);

  //test default value (should be true)
  cmdDistrib.addCommit(updateRequest, ccmd);
  boolean openSearcher = updateRequest.getParams().getBool(UpdateParams.OPEN_SEARCHER,false);
  assertTrue(openSearcher);

  //test openSearcher = false
  ccmd.openSearcher = false;
  
  cmdDistrib.addCommit(updateRequest, ccmd);
  openSearcher = updateRequest.getParams().getBool(UpdateParams.OPEN_SEARCHER,true);
  assertFalse(openSearcher);
}
 
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:SolrCmdDistributorTest.java

示例13: indexDoc

import org.apache.solr.client.solrj.request.UpdateRequest; //导入依赖的package包/类
protected void indexDoc(List<CloudJettyRunner> skipServers, Object... fields) throws IOException,
    SolrServerException {
  SolrInputDocument doc = new SolrInputDocument();
  
  addFields(doc, fields);
  addFields(doc, "rnd_b", true);
  
  controlClient.add(doc);
  
  UpdateRequest ureq = new UpdateRequest();
  ureq.add(doc);
  ModifiableSolrParams params = new ModifiableSolrParams();
  for (CloudJettyRunner skip : skipServers) {
    params.add("test.distrib.skip.servers", skip.url + "/");
  }
  ureq.setParams(params);
  ureq.process(cloudClient);
}
 
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:SyncSliceTest.java

示例14: performUpdate

import org.apache.solr.client.solrj.request.UpdateRequest; //导入依赖的package包/类
private void performUpdate(Delete obj) throws TranslatorException {
	Table table = obj.getTable().getMetadataObject();
	KeyRecord pk = table.getPrimaryKey();
	final String id = getRecordName(pk.getColumns().get(0));

	if (obj.getParameterValues() != null) {
		throw new TranslatorException(SolrPlugin.Event.TEIID20008, SolrPlugin.Util.gs(SolrPlugin.Event.TEIID20008));
	}
	
	SolrQueryExecution query = new SolrQueryExecution(ef, obj, this.executionContext, this.metadata, this.connection);
	query.execute();
	
	final UpdateRequest request = new UpdateRequest();
	query.walkDocuments(new SolrDocumentCallback() {
		@Override
		public void walk(SolrDocument doc) {
			SolrUpdateExecution.this.updateCount++;
			request.deleteById(doc.getFieldValue(id).toString());
		}
	});
	
	UpdateResponse response = this.connection.update(request);
	if (response.getStatus() != 0) {
		throw new TranslatorException(SolrPlugin.Event.TEIID20005, SolrPlugin.Util.gs(SolrPlugin.Event.TEIID20005, response.getStatus()));
	}		
}
 
开发者ID:kenweezy,项目名称:teiid,代码行数:27,代码来源:SolrUpdateExecution.java

示例15: testSimpleInsert

import org.apache.solr.client.solrj.request.UpdateRequest; //导入依赖的package包/类
@Test
public void testSimpleInsert() throws Exception {
	String query = "insert into example (price, weight, popularity, name, field) "
			+"VALUES ('1.10', '2.23', 5, 'teiid', 'any')";
	
	SolrInputDocument insert = new SolrInputDocument();
	insert.addField("price", 1.10f);
	insert.addField("weight", 2.23f);
	insert.addField("popularity", 5);
	insert.addField("name", "teiid");
	insert.addField("nis", "any");
	
	QueryResponse queryResponse = Mockito.mock(QueryResponse.class); 
	Mockito.stub(queryResponse.getResults()).toReturn(new SolrDocumentList());

	QueryResponse queryResponse2 = Mockito.mock(QueryResponse.class); 
	Mockito.stub(queryResponse2.getResults()).toReturn(new SolrDocumentList());
	
	UpdateRequest request = helpUpdate(query, queryResponse, queryResponse2);
	
	List<SolrInputDocument> docs = request.getDocuments();
	assertEquals(1, docs.size());
	assertEquals(insert.toString(), docs.get(0).toString());
}
 
开发者ID:kenweezy,项目名称:teiid,代码行数:25,代码来源:TestSolrUpdateExecution.java


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