Search in sources :

Example 21 with SegmentInfos

use of org.apache.lucene.index.SegmentInfos in project lucene-solr by apache.

the class IndexFetcher method hasUnusedFiles.

private boolean hasUnusedFiles(Directory indexDir, IndexCommit commit) throws IOException {
    String segmentsFileName = commit.getSegmentsFileName();
    SegmentInfos infos = SegmentInfos.readCommit(indexDir, segmentsFileName);
    Set<String> currentFiles = new HashSet<>(infos.files(true));
    String[] allFiles = indexDir.listAll();
    for (String file : allFiles) {
        if (!file.equals(segmentsFileName) && !currentFiles.contains(file) && !file.endsWith(".lock")) {
            LOG.info("Found unused file: " + file);
            return true;
        }
    }
    return false;
}
Also used : SegmentInfos(org.apache.lucene.index.SegmentInfos) HashSet(java.util.HashSet)

Example 22 with SegmentInfos

use of org.apache.lucene.index.SegmentInfos in project lucene-solr by apache.

the class TestPerfTasksLogic method testForceMerge.

/**
   * 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=RAMDirectory", "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());
    // first 20 reuters docs.
    int ndocsExpected = 20;
    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());
}
Also used : SegmentInfos(org.apache.lucene.index.SegmentInfos) IndexReader(org.apache.lucene.index.IndexReader)

Example 23 with SegmentInfos

use of org.apache.lucene.index.SegmentInfos in project lucene-solr by apache.

the class CommitIndexTaskTest method testCommitData.

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();
}
Also used : SegmentInfos(org.apache.lucene.index.SegmentInfos) PerfRunData(org.apache.lucene.benchmark.byTask.PerfRunData)

Aggregations

SegmentInfos (org.apache.lucene.index.SegmentInfos)23 IOException (java.io.IOException)9 IndexWriter (org.apache.lucene.index.IndexWriter)9 Term (org.apache.lucene.index.Term)8 IndexSearcher (org.apache.lucene.search.IndexSearcher)8 TermQuery (org.apache.lucene.search.TermQuery)7 Document (org.apache.lucene.document.Document)6 TextField (org.apache.lucene.document.TextField)6 DirectoryReader (org.apache.lucene.index.DirectoryReader)6 Directory (org.apache.lucene.store.Directory)6 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)5 SegmentCommitInfo (org.apache.lucene.index.SegmentCommitInfo)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 IndexReader (org.apache.lucene.index.IndexReader)4 Collectors (java.util.stream.Collectors)3 IntStream (java.util.stream.IntStream)3 Store (org.apache.lucene.document.Field.Store)3 StringField (org.apache.lucene.document.StringField)3 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)3