protected Object doBody(String segmentFileName) throws CorruptIndexException, IOException { read(directory, segmentFileName); return null; } }.run();
protected Object doBody(String segmentFileName) throws CorruptIndexException, IOException { read(directory, segmentFileName); return null; } }.run();
public IndexSplitter(File dir) throws IOException { this.dir = dir; fsDir = FSDirectory.open(dir); infos = new SegmentInfos(); infos.read(fsDir); }
public Object doBody() throws IOException { if (create) segmentInfos.write(directory); else segmentInfos.read(directory); return null; } }.run();
public static int getNumSegments(Directory idx) throws IOException { SegmentInfos infos = new SegmentInfos(); infos.read(idx); return infos.size(); }
public static int getNumSegments(Directory idx) throws IOException { SegmentInfos infos = new SegmentInfos(); infos.read(idx); return infos.size(); }
public static String getSegmentsInfo(Directory idx) { SegmentInfos infos = new SegmentInfos(); try { infos.read(idx); StringBuilder buf = new StringBuilder(); for (int i = 0; i < infos.size(); i++) { SegmentInfoPerCommit segInfo = infos.info(i); buf.append("[").append(segInfo.info.name).append(",numDoc:").append(segInfo.info.getDocCount()) .append(",numDel:").append(segInfo.getDelCount()).append("]"); } return buf.toString(); } catch (Exception e) { return e.toString(); } } }
public static int getNumSegments(Directory idx) throws IOException { SegmentInfos infos=new SegmentInfos(); infos.read(idx); return infos.size(); } public static String getSegmentsInfo(Directory idx)
public static String getSegmentsInfo(Directory idx) { SegmentInfos infos = new SegmentInfos(); try { infos.read(idx); StringBuilder buf = new StringBuilder(); for (int i = 0; i < infos.size(); i++) { SegmentInfoPerCommit segInfo = infos.info(i); buf.append("[").append(segInfo.info.name).append(",numDoc:").append(segInfo.info.getDocCount()) .append(",numDel:").append(segInfo.getDelCount()).append("]"); } return buf.toString(); } catch (Exception e) { return e.toString(); } } }
public static String getSegmentsInfo(Directory idx) { SegmentInfos infos=new SegmentInfos(); try { infos.read(idx); StringBuilder buf=new StringBuilder(); for(int i=0;i<infos.size(); i++) { SegmentInfo info = infos.info(i); buf.append("[").append(info.name).append(",numDoc:").append(info.docCount).append(",numDel:").append(info.getDelCount()).append("]"); } return buf.toString(); } catch (Exception e) { return e.toString(); } } }
protected Object doBody(String segmentFileName) throws CorruptIndexException, IOException { SegmentInfos infos = new SegmentInfos(); infos.read(directory, segmentFileName); DirectoryIndexReader newReader = doReopen(infos); if (DirectoryIndexReader.this != newReader) { newReader.init(directory, infos, closeDirectory, readOnly); newReader.deletionPolicy = deletionPolicy; } return newReader; } };
public static int getNumDocs(Directory dir) throws IOException { int count = 0; SegmentInfos sis = new SegmentInfos(); sis.read(dir); for (SegmentCommitInfo sci : sis) { count += sci.info.getDocCount() - sci.getDelCount(); } return count; }
protected Object doBody(String segmentFileName) throws CorruptIndexException, IOException { SegmentInfos infos = new SegmentInfos(); infos.read(directory, segmentFileName); DirectoryIndexReader newReader = doReopen(infos); if (DirectoryIndexReader.this != newReader) { newReader.init(directory, infos, closeDirectory, readOnly); newReader.deletionPolicy = deletionPolicy; } return newReader; } };
public static int getNumDocs(Directory dir) throws IOException { int count = 0; SegmentInfos sis = new SegmentInfos(); sis.read(dir); for (SegmentCommitInfo sci : sis) { count += sci.info.getDocCount() - sci.getDelCount(); } return count; }
/** Merges all segments from an array of indexes into this index. * * <p>This may be used to parallelize batch indexing. A large document * collection can be broken into sub-collections. Each sub-collection can be * indexed in parallel, on a different thread, process or machine. The * complete index can then be created by merging sub-collection indexes * with this method. * * <p>After this completes, the index is optimized. */ public synchronized void addIndexes(Directory[] dirs) throws IOException { optimize(); // start with zero or 1 seg for (int i = 0; i < dirs.length; i++) { SegmentInfos sis = new SegmentInfos(); // read infos from dir sis.read(dirs[i]); for (int j = 0; j < sis.size(); j++) { segmentInfos.addElement(sis.info(j)); // add each info } } optimize(); // final cleanup }
/** * Returns <code>true</code> if all the segments of the directory are in un-compound format. * Will return <code>true</code> if the index does not exists or there are no segments. */ public static boolean isUnCompound(final Directory directory) throws IOException { if (!IndexReader.indexExists(directory)) { return true; } final SegmentInfos segmentInfos = new SegmentInfos(); segmentInfos.read(directory); if (segmentInfos.isEmpty()) { return true; } for (int i = 0; i < segmentInfos.size(); i++) { SegmentInfo segmentInfo = segmentInfos.info(i); if (segmentInfo.getUseCompoundFile()) { return false; } } return true; }
/** * Returns <code>true</code> if all the segments of the directory are in compound format. * Will return <code>true</code> if the index does not exists or there are no segments. */ public static boolean isCompound(final Directory directory) throws IOException { if (!IndexReader.indexExists(directory)) { return true; } final SegmentInfos segmentInfos = new SegmentInfos(); segmentInfos.read(directory); if (segmentInfos.isEmpty()) { return true; } for (int i = 0; i < segmentInfos.size(); i++) { SegmentInfo segmentInfo = segmentInfos.info(i); if (!segmentInfo.getUseCompoundFile()) { return false; } } return true; }
protected Object doBody(String segmentFileName) throws CorruptIndexException, IOException { SegmentInfos infos = new SegmentInfos(); infos.read(directory, segmentFileName); DirectoryIndexReader reader; if (infos.size() == 1) { // index is optimized reader = SegmentReader.get(readOnly, infos, infos.info(0), false); } else if (readOnly) { reader = new ReadOnlyMultiSegmentReader(directory, infos, false); } else { reader = new MultiSegmentReader(directory, infos, false, false); } reader.setDeletionPolicy(deletionPolicy); reader.closeDirectory = closeDirectory; return reader; } };
protected Object doBody(String segmentFileName) throws CorruptIndexException, IOException { SegmentInfos infos = new SegmentInfos(); infos.read(directory, segmentFileName); DirectoryIndexReader reader; if (infos.size() == 1) { // index is optimized reader = SegmentReader.get(readOnly, infos, infos.info(0), false); } else if (readOnly) { reader = new ReadOnlyMultiSegmentReader(directory, infos, false); } else { reader = new MultiSegmentReader(directory, infos, false, false); } reader.setDeletionPolicy(deletionPolicy); reader.closeDirectory = closeDirectory; return reader; } };
public Object doBody() throws IOException { SegmentInfos infos = new SegmentInfos(); infos.read(directory); if (infos.size() == 1) { // index is optimized return new SegmentReader(infos, infos.info(0), closeDirectory); } else { IndexReader[] readers = new IndexReader[infos.size()]; for (int i = 0; i < infos.size(); i++) readers[i] = new SegmentReader(infos.info(i)); return new MultiReader(directory, infos, closeDirectory, readers); } } }.run();