當前位置: 首頁>>代碼示例>>Java>>正文


Java SolrClient.commit方法代碼示例

本文整理匯總了Java中org.apache.solr.client.solrj.SolrClient.commit方法的典型用法代碼示例。如果您正苦於以下問題:Java SolrClient.commit方法的具體用法?Java SolrClient.commit怎麽用?Java SolrClient.commit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.solr.client.solrj.SolrClient的用法示例。


在下文中一共展示了SolrClient.commit方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testRuntimeLib

import org.apache.solr.client.solrj.SolrClient; //導入方法依賴的package包/類
@Test
public void testRuntimeLib() throws SolrServerException, IOException {
    SearchServer server = testSearchServer.getSearchServer();

    SolrClient client = (SolrClient) server.getBackend();

    SolrInputDocument document = new SolrInputDocument();
    document.setField("_id_", "1");
    document.setField("_type_", "doc");
    document.setField("dynamic_multi_facet_string_f1", "test");
    document.setField("dynamic_multi_facet_string_f2", "hello");

    client.add(document);
    client.commit();

    SolrQuery query = new SolrQuery("t");
    query.setRequestHandler("/suggester");
    query.set("suggestion.df", "facets");
    query.set("suggestion.field", "dynamic_multi_facet_string_f1");

    QueryResponse response = client.query(query);

    assertEquals(1, ((HashMap) response.getResponse().get("suggestions")).get("suggestion_count"));
}
 
開發者ID:RBMHTechnology,項目名稱:vind,代碼行數:25,代碼來源:TestServerTest.java

示例2: updateDocs

import org.apache.solr.client.solrj.SolrClient; //導入方法依賴的package包/類
private void updateDocs( List<SolrInputDocument> docs, boolean commit ) throws SolrServerException, IOException {
  LOG.debug( "updateDocs " + docs.size( ) );
  SolrClient suggestClient = getSuggestClient( );
  try {
    UpdateResponse resp = suggestClient.add( suggesterCollection, docs );
  }
  catch ( SolrServerException sse ) {
    LOG.error( "Got SolrServerExeption " + sse );
    throw sse;
  }
    
  if (commit) {
    LOG.debug( "committing to " + suggestHost );
    suggestClient.commit( suggesterCollection );
  }
  // check resp - if not OK, throw an Exception??
}
 
開發者ID:detnavillus,項目名稱:multifield_suggester_code,代碼行數:18,代碼來源:SuggestCollectionBuilder.java

示例3: shutdownGracefully

import org.apache.solr.client.solrj.SolrClient; //導入方法依賴的package包/類
private void shutdownGracefully(SolrClient client) throws SolrServerException, IOException {
    if (client != null) {
        LOGGER.info("Shutting down solr client: {}", client);
        client.commit(false, false);
        client.close();
    }
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:8,代碼來源:MCRSolrCore.java

示例4: deleteById

import org.apache.solr.client.solrj.SolrClient; //導入方法依賴的package包/類
/**
 * Deletes a list of documents by unique ID. Also removes any nested document of that ID.
 *
 * @param solrIDs
 *            the list of solr document IDs to delete
 */
public static UpdateResponse deleteById(String... solrIDs) {
    if (solrIDs == null || solrIDs.length == 0) {
        return null;
    }
    SolrClient solrClient = MCRSolrClientFactory.getSolrClient();
    UpdateResponse updateResponse = null;
    long start = System.currentTimeMillis();
    try {
        LOGGER.debug("Deleting \"{}\" from solr", Arrays.asList(solrIDs));
        UpdateRequest req = new UpdateRequest();
        //delete all documents rooted at this id
        if (MCRSolrUtils.useNestedDocuments()) {
            StringBuilder deleteQuery = new StringBuilder("_root_:(");
            for (String solrID : solrIDs) {
                deleteQuery.append('"');
                deleteQuery.append(MCRSolrUtils.escapeSearchValue(solrID));
                deleteQuery.append("\" ");
            }
            deleteQuery.setCharAt(deleteQuery.length() - 1, ')');
            req.deleteByQuery(deleteQuery.toString());
        }
        //for document without nested
        req.deleteById(Arrays.asList(solrIDs));
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Delete request: {}", req.getXML());
        }
        updateResponse = req.process(solrClient);
        solrClient.commit();
    } catch (Exception e) {
        LOGGER.error("Error deleting document from solr", e);
    }
    long end = System.currentTimeMillis();
    MCRSolrIndexStatistic operations = MCRSolrIndexStatisticCollector.OPERATIONS;
    operations.addDocument(1);
    operations.addTime(end - start);
    return updateResponse;

}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:45,代碼來源:MCRSolrIndexer.java

示例5: deleteDerivate

import org.apache.solr.client.solrj.SolrClient; //導入方法依賴的package包/類
/**
 * Convenient method to delete a derivate and all its files at once.
 *
 * @param id the derivate id
 * @return the solr response
 */
public static UpdateResponse deleteDerivate(String id) {
    if (id == null) {
        return null;
    }
    SolrClient solrClient = MCRSolrClientFactory.getSolrClient();
    UpdateResponse updateResponse = null;
    long start = System.currentTimeMillis();
    try {
        LOGGER.debug("Deleting derivate \"{}\" from solr", id);
        UpdateRequest req = new UpdateRequest();
        StringBuilder deleteQuery = new StringBuilder();
        deleteQuery.append("id:").append(id).append(" ");
        deleteQuery.append("derivateID:").append(id);
        if (MCRSolrUtils.useNestedDocuments()) {
            deleteQuery.append(" ").append("_root_:").append(id);
        }
        req.deleteByQuery(deleteQuery.toString());
        updateResponse = req.process(solrClient);
        solrClient.commit();
    } catch (Exception e) {
        LOGGER.error("Error deleting document from solr", e);
    }
    long end = System.currentTimeMillis();
    MCRSolrIndexStatistic operations = MCRSolrIndexStatisticCollector.OPERATIONS;
    operations.addDocument(1);
    operations.addTime(end - start);
    return updateResponse;
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:35,代碼來源:MCRSolrIndexer.java

示例6: commit

import org.apache.solr.client.solrj.SolrClient; //導入方法依賴的package包/類
@Override
public void commit() throws IOException {
  push();
  try {
    for (SolrClient solrClient : solrClients) {
      solrClient.commit();
    }
  } catch (final SolrServerException e) {
    LOG.error("Failed to commit solr connection: " + e.getMessage()); // FIXME
  }
}
 
開發者ID:jorcox,項目名稱:GeoCrawler,代碼行數:12,代碼來源:SolrIndexWriter.java

示例7: setUp

import org.apache.solr.client.solrj.SolrClient; //導入方法依賴的package包/類
/**
 * Indexes some sample data as test fixture.
 * 
 * @throws Exception hopefully never, otherwise the test will fail.
 */
@Before
public void setUp() throws Exception {
	super.setUp();
	final SolrClient indexer = getSolrClient();
	final SolrInputDocument book1 = new SolrInputDocument();
	book1.setField("id","1");
	book1.setField("title","Apache Solr Essentials");
	book1.setField("author","Andrea Gazzarini");
	
	indexer.add(book1);
	indexer.commit();
}
 
開發者ID:spaziocodice,項目名稱:invisible-queries-request-handler,代碼行數:18,代碼來源:FacadeRequestHandler_IT.java

示例8: tearDown

import org.apache.solr.client.solrj.SolrClient; //導入方法依賴的package包/類
@After 
public void tearDown() throws Exception {
	super.tearDown();
	final SolrClient indexer = getSolrClient();
	indexer.deleteByQuery("*:*");
	indexer.commit();
}
 
開發者ID:spaziocodice,項目名稱:invisible-queries-request-handler,代碼行數:8,代碼來源:FacadeRequestHandler_IT.java

示例9: process

import org.apache.solr.client.solrj.SolrClient; //導入方法依賴的package包/類
@Override
public void process(Exchange exchange) throws Exception {

    String operation = (String) exchange.getIn().getHeader(SolrConstants.OPERATION);

    if (operation == null) {
        throw new IllegalArgumentException(SolrConstants.OPERATION + " header is missing");
    }

    SolrClient serverToUse = getBestSolrServer(operation);

    if (operation.equalsIgnoreCase(SolrConstants.OPERATION_INSERT)) {
        insert(exchange, serverToUse);
    } else if (operation.equalsIgnoreCase(SolrConstants.OPERATION_INSERT_STREAMING)) {
        insert(exchange, serverToUse);
    } else if (operation.equalsIgnoreCase(SolrConstants.OPERATION_DELETE_BY_ID)) {
        serverToUse.deleteById(exchange.getIn().getBody(String.class));
    } else if (operation.equalsIgnoreCase(SolrConstants.OPERATION_DELETE_BY_QUERY)) {
        serverToUse.deleteByQuery(exchange.getIn().getBody(String.class));
    } else if (operation.equalsIgnoreCase(SolrConstants.OPERATION_ADD_BEAN)) {
        serverToUse.addBean(exchange.getIn().getBody());
    } else if (operation.equalsIgnoreCase(SolrConstants.OPERATION_ADD_BEANS)) {
        serverToUse.addBeans(exchange.getIn().getBody(Collection.class));
    } else if (operation.equalsIgnoreCase(SolrConstants.OPERATION_COMMIT)) {
        serverToUse.commit();
    } else if (operation.equalsIgnoreCase(SolrConstants.OPERATION_ROLLBACK)) {
        serverToUse.rollback();
    } else if (operation.equalsIgnoreCase(SolrConstants.OPERATION_OPTIMIZE)) {
        serverToUse.optimize();
    } else {
        throw new IllegalArgumentException(
                SolrConstants.OPERATION + " header value '" + operation + "' is not supported");
    }
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:35,代碼來源:SolrProducer.java


注:本文中的org.apache.solr.client.solrj.SolrClient.commit方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。