Java Code Examples for org.apache.lucene.index.SegmentInfos#readLatestCommit()
The following examples show how to use
org.apache.lucene.index.SegmentInfos#readLatestCommit() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestSearcherTaxonomyManager.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testExceptionDuringRefresh() throws Exception { Directory indexDir = newDirectory(); Directory taxoDir = newDirectory(); IndexWriter w = new IndexWriter(indexDir, newIndexWriterConfig(new MockAnalyzer(random()))); DirectoryTaxonomyWriter tw = new DirectoryTaxonomyWriter(taxoDir); w.commit(); tw.commit(); SearcherTaxonomyManager mgr = new SearcherTaxonomyManager(indexDir, taxoDir, null); tw.addCategory(new FacetLabel("a", "b")); w.addDocument(new Document()); tw.commit(); w.commit(); // intentionally corrupt the taxo index: SegmentInfos infos = SegmentInfos.readLatestCommit(taxoDir); taxoDir.deleteFile(infos.getSegmentsFileName()); expectThrows(IndexNotFoundException.class, mgr::maybeRefreshBlocking); IOUtils.close(w, tw, mgr, indexDir, taxoDir); }
Example 2
Source File: CommitIndexTaskTest.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testCommitData() throws Exception { PerfRunData runData = createPerfRunData(); new CreateIndexTask(runData).doLogic(); CommitIndexTask task = new CommitIndexTask(runData); task.setParams("params"); task.doLogic(); SegmentInfos infos = SegmentInfos.readLatestCommit(runData.getDirectory()); assertEquals("params", infos.getUserData().get(OpenReaderTask.USER_DATA)); new CloseIndexTask(runData).doLogic(); }
Example 3
Source File: TestPerfTasksLogic.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Test that we can call forceMerge(maxNumSegments). */ public void testForceMerge() throws Exception { // 1. alg definition (required in every "logic" test) String algLines[] = { "# ----- properties ", "content.source=org.apache.lucene.benchmark.byTask.feeds.LineDocSource", "docs.file=" + getReuters20LinesFile(), "content.source.log.step=3", "ram.flush.mb=-1", "max.buffered=3", "doc.term.vector=false", "content.source.forever=false", "directory=ByteBuffersDirectory", "merge.policy=org.apache.lucene.index.LogDocMergePolicy", "doc.stored=false", "doc.tokenized=false", "debug.level=1", "# ----- alg ", "{ \"Rounds\"", " ResetSystemErase", " CreateIndex", " { \"AddDocs\" AddDoc > : * ", " ForceMerge(3)", " CloseIndex()", "} : 2", }; // 2. execute the algorithm (required in every "logic" test) Benchmark benchmark = execBenchmark(algLines); // 3. test number of docs in the index IndexReader ir = DirectoryReader.open(benchmark.getRunData().getDirectory()); int ndocsExpected = 20; // first 20 reuters docs. assertEquals("wrong number of docs in the index!", ndocsExpected, ir.numDocs()); ir.close(); // Make sure we have 3 segments: SegmentInfos infos = SegmentInfos.readLatestCommit(benchmark.getRunData().getDirectory()); assertEquals(3, infos.size()); }
Example 4
Source File: DirectoryTaxonomyWriter.java From lucene-solr with Apache License 2.0 | 4 votes |
/** Reads the commit data from a Directory. */ private static Map<String, String> readCommitData(Directory dir) throws IOException { SegmentInfos infos = SegmentInfos.readLatestCommit(dir); return infos.getUserData(); }
Example 5
Source File: TestDirectoryTaxonomyWriter.java From lucene-solr with Apache License 2.0 | 4 votes |
private long getEpoch(Directory taxoDir) throws IOException { SegmentInfos infos = SegmentInfos.readLatestCommit(taxoDir); return Long.parseLong(infos.getUserData().get(DirectoryTaxonomyWriter.INDEX_EPOCH)); }
Example 6
Source File: Lucene.java From crate with Apache License 2.0 | 4 votes |
/** * Reads the segments infos, failing if it fails to load */ public static SegmentInfos readSegmentInfos(Directory directory) throws IOException { return SegmentInfos.readLatestCommit(directory); }