Package org.apache.lucene.index

Examples of org.apache.lucene.index.IndexCommit


    return new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy(), snapshots);
  }

  protected void assertSnapshotExists(Directory dir, SnapshotDeletionPolicy sdp, int numSnapshots) throws Exception {
    for (int i = 0; i < numSnapshots; i++) {
      IndexCommit snapshot = sdp.getSnapshot("snapshot" + i);
      checkMaxDoc(snapshot, i + 1);
      checkSnapshotExists(dir, snapshot);
    }
  }
View Full Code Here


    writer.addDocument(new Document());
    writer.commit();
   
    String s1 = "s1";
    String s2 = "s2";
    IndexCommit ic1 = sdp.snapshot(s1);
    IndexCommit ic2 = sdp.snapshot(s2);
    assertTrue(ic1 == ic2); // should be the same instance
   
    // create another commit
    writer.addDocument(new Document());
    writer.commit();
View Full Code Here

    Directory dir = newDirectory();
    SnapshotDeletionPolicy sdp = getDeletionPolicy();
    IndexWriter writer = new IndexWriter(dir, getConfig(random, sdp));
    writer.addDocument(new Document());
    writer.commit();
    IndexCommit ic = sdp.snapshot("s1");

    // create another commit, not snapshotted.
    writer.addDocument(new Document());
    writer.close();

    // open a new writer w/ KeepOnlyLastCommit policy, so it will delete "s1"
    // commit.
    new IndexWriter(dir, getConfig(random, null)).close();
   
    assertFalse("snapshotted commit should not exist", dir.fileExists(ic.getSegmentsFileName()));
   
    // Now reinit SDP from the commits in the index - the snapshot id should not
    // exist anymore.
    sdp = getDeletionPolicy(sdp.getSnapshots());
    new IndexWriter(dir, getConfig(random, sdp)).close();
View Full Code Here

  public static IndexReader openCommitPoint(String userData, Directory dir, Config config, boolean readOnly) throws IOException {
    IndexReader r = null;
    Collection commits = IndexReader.listCommits(dir);
    Iterator i = commits.iterator();
    while (i.hasNext()) {
      IndexCommit ic = (IndexCommit)i.next();
      Map map = ic.getUserData();
      String ud = null;
      if (map != null) {
        ud = (String)map.get(USER_DATA);
      }
      if (ud != null && ud.equals(userData)) {
View Full Code Here

   * directory. It suppresses any exceptions that occur, as this can be retried
   * the next time.
   */
  public static void cleanupOldIndexFiles(Directory dir, String segmentsFile) {
    try {
      IndexCommit commit = getLastCommit(dir);
      // commit == null means weird IO errors occurred, ignore them
      // if there were any IO errors reading the expected commit point (i.e.
      // segments files mismatch), then ignore that commit either.
      if (commit != null && commit.getSegmentsFileName().equals(segmentsFile)) {
        Set<String> commitFiles = new HashSet<>();
        commitFiles.addAll(commit.getFileNames());
        commitFiles.add(IndexFileNames.SEGMENTS_GEN);
        Matcher matcher = IndexFileNames.CODEC_FILE_PATTERN.matcher("");
        for (String file : dir.listAll()) {
          if (!commitFiles.contains(file)
              && (matcher.reset(file).matches() || file.startsWith(IndexFileNames.SEGMENTS))) {
View Full Code Here

    this.indexDir = indexDir;
    currentRevisionFiles = null;
    currentVersion = null;
    if (DirectoryReader.indexExists(indexDir)) {
      final List<IndexCommit> commits = DirectoryReader.listCommits(indexDir);
      final IndexCommit commit = commits.get(commits.size() - 1);
      currentRevisionFiles = IndexRevision.revisionFiles(commit);
      currentVersion = IndexRevision.revisionVersion(commit);
      final InfoStream infoStream = InfoStream.getDefault();
      if (infoStream.isEnabled(INFO_STREAM_COMPONENT)) {
        infoStream.message(INFO_STREAM_COMPONENT, "constructor(): currentVersion=" + currentVersion
View Full Code Here

 
  @Override
  public InputStream open(String source, String fileName) throws IOException {
    assert source.equals(INDEX_SOURCE) || source.equals(TAXONOMY_SOURCE) : "invalid source; expected=(" + INDEX_SOURCE
    + " or " + TAXONOMY_SOURCE + ") got=" + source;
    IndexCommit ic = source.equals(INDEX_SOURCE) ? indexCommit : taxoCommit;
    return new IndexInputInputStream(ic.getDirectory().openInput(fileName, IOContext.READONCE));
  }
View Full Code Here

    if (indexExists != taxoExists) {
      throw new IllegalStateException("search and taxonomy indexes must either both exist or not: index=" + indexExists
          + " taxo=" + taxoExists);
    }
    if (indexExists) { // both indexes exist
      final IndexCommit indexCommit = IndexReplicationHandler.getLastCommit(indexDir);
      final IndexCommit taxoCommit = IndexReplicationHandler.getLastCommit(taxoDir);
      currentRevisionFiles = IndexAndTaxonomyRevision.revisionFiles(indexCommit, taxoCommit);
      currentVersion = IndexAndTaxonomyRevision.revisionVersion(indexCommit, taxoCommit);
      final InfoStream infoStream = InfoStream.getDefault();
      if (infoStream.isEnabled(INFO_STREAM_COMPONENT)) {
        infoStream.message(INFO_STREAM_COMPONENT, "constructor(): currentVersion=" + currentVersion
View Full Code Here

  @Override
  public int doLogic() throws IOException {
    PerfRunData runData = getRunData();
    Config config = runData.getConfig();
    final IndexCommit ic;
    if (commitUserData != null) {
      ic = OpenReaderTask.findIndexCommit(runData.getDirectory(), commitUserData);
    } else {
      ic = null;
    }
View Full Code Here

  @Override
  public int doLogic() throws IOException {
    PerfRunData runData = getRunData();
    Config config = runData.getConfig();
    final IndexCommit ic;
    if (commitUserData != null) {
      ic = OpenReaderTask.findIndexCommit(runData.getDirectory(), commitUserData);
    } else {
      ic = null;
    }
View Full Code Here

TOP

Related Classes of org.apache.lucene.index.IndexCommit

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.