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


Java EmbeddedSolrServer.commit方法代碼示例

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


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

示例1: addNewDoc

import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer; //導入方法依賴的package包/類
public static void addNewDoc(EmbeddedSolrServer server, String docId, String docTitle,
                             String text, JATEProperties jateProperties, boolean commit)
        throws IOException, SolrServerException, JATEException {
    SolrInputDocument newDoc = new SolrInputDocument();
    newDoc.addField("id", docId);
    newDoc.addField("title_s", docTitle);
    newDoc.addField("text", text);

    newDoc.addField(jateProperties.getSolrFieldNameJATENGramInfo(), text);
    newDoc.addField(jateProperties.getSolrFieldNameJATECTerms(), text);

    server.add(newDoc);

    if (commit) {
        server.commit();
    }
}
 
開發者ID:ziqizhang,項目名稱:jate,代碼行數:18,代碼來源:JATEUtil.java

示例2: runEmbeddedExample

import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer; //導入方法依賴的package包/類
private static void runEmbeddedExample(String solrHomePath) {
    File coreConfig = new File(solrHomePath, "solr-solrj.xml" );
    CoreContainer container = null;
    try {
        container = new CoreContainer( solrHomePath, coreConfig);
    } catch (FileNotFoundException ex) {throw new RuntimeException(ex);}
    EmbeddedSolrServer solr = new EmbeddedSolrServer( container, "solrj" );
    listCollectionContent(solr, "Running in embedded mode");
    Email doc = new Email();
    doc.id = "email4";
    doc.addr_from = "[email protected]";
    doc.addr_to = new String[]{"[email protected]", "[email protected]"};
    doc.subject = "Thanks (Was Re: Updating vacancy description)";
    try {
        solr.addBean(doc);
        solr.commit();
    } catch (Exception e) {
        //Catch and ignore over-generic exception. Do NOT do this in production
        e.printStackTrace();
    }
    listCollectionContent(solr, "Added record in embedded mode");

    solr.shutdown();
}
 
開發者ID:arafalov,項目名稱:solr-indexing-book,代碼行數:25,代碼來源:ClientSolrj.java

示例3: setUp

import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer; //導入方法依賴的package包/類
@Before
@Override
public void setUp() throws Exception {
    // set up an embedded solr server
    super.setUp();
    initCore(getResourcePath(getConfigString()), getResourcePath(getSchemaString()));
    server = new EmbeddedSolrServer(h.getCoreContainer(), h.getCore().getName());
    instance = new SearchResultsDaoImpl(server, new VloConfig() {

        @Override
        public List<String> getFacetsInSearch() {
            return ImmutableList.of(FIELD_COLLECTION, FIELD_COUNTRY);
        }

    });

    // add some documents
    int id = 1;
    CMDIData cmdiData = new CMDIData();
    cmdiData.addDocField(FIELD_COLLECTION, "Collection1", false);
    cmdiData.addDocField(FIELD_COUNTRY, "Country1", false);
    SolrInputDocument document = cmdiData.getSolrDocument();
    document.addField("id", Integer.toString(id++));
    server.add(document);

    cmdiData = new CMDIData();
    cmdiData.addDocField(FIELD_COLLECTION, "Collection1", false);
    cmdiData.addDocField(FIELD_COUNTRY, "Country2", false);
    document = cmdiData.getSolrDocument();
    document.addField("id", Integer.toString(id++));
    server.add(document);

    server.commit();
}
 
開發者ID:acdh-oeaw,項目名稱:vlo-curation,代碼行數:35,代碼來源:SearchResultsDaoImplTest.java

示例4: startup

import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer; //導入方法依賴的package包/類
@Before
public void startup() throws IOException, SolrServerException {
  // start an embedded solr instance
  coreContainer = new CoreContainer("solr");
  coreContainer.load();
  solr = new EmbeddedSolrServer(coreContainer, "heron");
  solr.deleteByQuery("*:*");
  solr.commit();
}
 
開發者ID:safarijv,項目名稱:ifpress-solr-plugin,代碼行數:10,代碼來源:HeronSolrTest.java

示例5: embeddedSolrServer

import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer; //導入方法依賴的package包/類
/**
 * Uses the {@link EmbeddedSolrServer} to index some data to Solr.
 * 
 * @throws Exception in case of I/O or index failure.
 */
@Test
public void embeddedSolrServer() throws Exception {
	// 1. Create a new (local) container using "solr.solr.home" and "solr.data.dir" system property.
	// Note that we need to define a dedicated solr.data.dir for this test method because
	// otherwise we would end in a lock conflict (the embedded Solr instance is running) 
	System.setProperty("solr.solr.home", "src/solr/solr-home");
	System.setProperty("solr.data.dir", new File("target/solr-embedded-solr").getAbsolutePath());
	CoreContainer container = new CoreContainer();
	container.load();
	
	System.out.println(container.getAllCoreNames());
	
	// 2. Create a new instance of (Embedded)SolrServer 
	solr = new EmbeddedSolrServer(container, "example");
	
	// 3. Create some data
	final List<SolrInputDocument> albums = sampleData();
	
	// 4. Add those data
	solr.add(albums);
	
	// 5. Commit
	solr.commit();

	// 6. Verify
	verify();
}
 
開發者ID:agazzarini,項目名稱:apache-solr-essentials,代碼行數:33,代碼來源:SolrServersITCase.java

示例6: testSplitByCores

import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer; //導入方法依賴的package包/類
@Test
public void testSplitByCores() throws Exception {
  // add two docs
  String id1 = "dorothy";
  assertU(adoc("id", id1));
  String id2 = "kansas";
  assertU(adoc("id", id2));
  assertU(commit());
  assertJQ(req("q", "*:*"), "/response/numFound==2");
  List<DocRouter.Range> ranges = getRanges(id1, id2);

  SolrCore core1 = null, core2 = null;
  try {
    String instanceDir = h.getCore().getCoreDescriptor().getInstanceDir();

    CoreDescriptor dcore1 = buildCoreDescriptor(h.getCoreContainer(), "split1", instanceDir)
        .withDataDir(indexDir1.getAbsolutePath()).withSchema("schema12.xml").build();
    core1 = h.getCoreContainer().create(dcore1);

    CoreDescriptor dcore2 = buildCoreDescriptor(h.getCoreContainer(), "split2", instanceDir)
        .withDataDir(indexDir2.getAbsolutePath()).withSchema("schema12.xml").build();
    core2 = h.getCoreContainer().create(dcore2);

    LocalSolrQueryRequest request = null;
    try {
      request = lrf.makeRequest("q", "dummy");

      SplitIndexCommand command = new SplitIndexCommand(request, null, Lists.newArrayList(core1, core2), ranges, new PlainIdRouter(), null, null);
      new SolrIndexSplitter(command).split();
    } finally {
      if (request != null) request.close();
    }
    EmbeddedSolrServer server1 = new EmbeddedSolrServer(h.getCoreContainer(), "split1");
    EmbeddedSolrServer server2 = new EmbeddedSolrServer(h.getCoreContainer(), "split2");
    server1.commit(true, true);
    server2.commit(true, true);
    assertEquals("id:dorothy should be present in split index1", 1, server1.query(new SolrQuery("id:dorothy")).getResults().getNumFound());
    assertEquals("id:kansas should not be present in split index1", 0, server1.query(new SolrQuery("id:kansas")).getResults().getNumFound());
    assertEquals("id:dorothy should not be present in split index2", 0, server2.query(new SolrQuery("id:dorothy")).getResults().getNumFound());
    assertEquals("id:kansas should be present in split index2", 1, server2.query(new SolrQuery("id:kansas")).getResults().getNumFound());
  } finally {
    h.getCoreContainer().unload("split2");
    h.getCoreContainer().unload("split1");
  }
}
 
開發者ID:europeana,項目名稱:search,代碼行數:46,代碼來源:SolrIndexSplitterTest.java

示例7: testSplitByCores

import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer; //導入方法依賴的package包/類
@Test
public void testSplitByCores() throws Exception {
  // add two docs
  String id1 = "dorothy";
  assertU(adoc("id", id1));
  String id2 = "kansas";
  assertU(adoc("id", id2));
  assertU(commit());
  assertJQ(req("q", "*:*"), "/response/numFound==2");
  List<DocRouter.Range> ranges = getRanges(id1, id2);

  SolrCore core1 = null, core2 = null;
  try {
    CoreDescriptor dcore1 = new CoreDescriptor(h.getCoreContainer(), "split1", h.getCore().getCoreDescriptor().getInstanceDir());
    dcore1.setDataDir(indexDir1.getAbsolutePath());
    dcore1.setSchemaName("schema12.xml");
    core1 = h.getCoreContainer().create(dcore1);
    h.getCoreContainer().register(core1, false);

    CoreDescriptor dcore2 = new CoreDescriptor(h.getCoreContainer(), "split2", h.getCore().getCoreDescriptor().getInstanceDir());
    dcore2.setDataDir(indexDir2.getAbsolutePath());
    dcore2.setSchemaName("schema12.xml");
    core2 = h.getCoreContainer().create(dcore2);
    h.getCoreContainer().register(core2, false);

    LocalSolrQueryRequest request = null;
    try {
      request = lrf.makeRequest("q", "dummy");

      SplitIndexCommand command = new SplitIndexCommand(request, null, Lists.newArrayList(core1, core2), ranges);
      new SolrIndexSplitter(command).split();
    } finally {
      if (request != null) request.close();
    }
    EmbeddedSolrServer server1 = new EmbeddedSolrServer(h.getCoreContainer(), "split1");
    EmbeddedSolrServer server2 = new EmbeddedSolrServer(h.getCoreContainer(), "split2");
    server1.commit(true, true);
    server2.commit(true, true);
    assertEquals("id:dorothy should be present in split index1", 1, server1.query(new SolrQuery("id:dorothy")).getResults().getNumFound());
    assertEquals("id:kansas should not be present in split index1", 0, server1.query(new SolrQuery("id:kansas")).getResults().getNumFound());
    assertEquals("id:dorothy should not be present in split index2", 0, server2.query(new SolrQuery("id:dorothy")).getResults().getNumFound());
    assertEquals("id:kansas should be present in split index2", 1, server2.query(new SolrQuery("id:kansas")).getResults().getNumFound());
  } finally {
    h.getCoreContainer().remove("split2");
    h.getCoreContainer().remove("split1");
    if (core2 != null) core2.close();
    if (core1 != null) core1.close();
  }
}
 
開發者ID:pkarmstr,項目名稱:NYBC,代碼行數:50,代碼來源:SolrIndexSplitterTest.java


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