Java Code Examples for org.apache.lucene.index.IndexCommit#getSegmentCount()
The following examples show how to use
org.apache.lucene.index.IndexCommit#getSegmentCount() .
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: Commit.java From lucene-solr with Apache License 2.0 | 5 votes |
static Commit of(IndexCommit ic) { Commit commit = new Commit(); commit.generation = ic.getGeneration(); commit.isDeleted = ic.isDeleted(); commit.segCount = ic.getSegmentCount(); try { commit.userData = IndexUtils.getCommitUserData(ic); } catch (IOException e) { } return commit; }
Example 2
Source File: SolrDeletionPolicy.java From lucene-solr with Apache License 2.0 | 4 votes |
private void updateCommits(List<? extends IndexCommit> commits) { // to be safe, we should only call delete on a commit point passed to us // in this specific call (may be across diff IndexWriter instances). // this will happen rarely, so just synchronize everything // for safety and to avoid race conditions synchronized (this) { long maxCommitAgeTimeStamp = -1L; IndexCommit newest = commits.get(commits.size() - 1); if (log.isDebugEnabled()) { log.debug("newest commit generation = {}", newest.getGeneration()); } int singleSegKept = (newest.getSegmentCount() == 1) ? 1 : 0; int totalKept = 1; // work our way from newest to oldest, skipping the first since we always want to keep it. for (int i=commits.size()-2; i>=0; i--) { IndexCommit commit = commits.get(i); // delete anything too old, regardless of other policies try { if (maxCommitAge != null) { if (maxCommitAgeTimeStamp==-1) { DateMathParser dmp = new DateMathParser(DateMathParser.UTC); maxCommitAgeTimeStamp = dmp.parseMath(maxCommitAge).getTime(); } if (IndexDeletionPolicyWrapper.getCommitTimestamp(commit) < maxCommitAgeTimeStamp) { commit.delete(); continue; } } } catch (Exception e) { log.warn("Exception while checking commit point's age for deletion", e); } if (singleSegKept < maxOptimizedCommitsToKeep && commit.getSegmentCount() == 1) { totalKept++; singleSegKept++; continue; } if (totalKept < maxCommitsToKeep) { totalKept++; continue; } commit.delete(); } } // end synchronized }