Last active
December 22, 2015 10:48
-
-
Save jpountz/6461246 to your computer and use it in GitHub Desktop.
File to restore a corrupted segment if the stored fields are not corrupted.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Set codec, dir and segmentName accordingly to the segment you are trying to restore | |
Codec codec = new Lucene42Codec(); | |
Directory dir = FSDirectory.open(new File("/tmp/test")); | |
String segmentName = "_0"; | |
IOContext ioContext = new IOContext(); | |
SegmentInfo segmentInfos = codec.segmentInfoFormat().getSegmentInfoReader().read(dir, segmentName, ioContext); | |
Directory segmentDir; | |
if (segmentInfos.getUseCompoundFile()) { | |
segmentDir = new CompoundFileDirectory(dir, IndexFileNames.segmentFileName(segmentName, "", IndexFileNames.COMPOUND_FILE_EXTENSION), ioContext, false); | |
} else { | |
segmentDir = dir; | |
} | |
FieldInfos fieldInfos = codec.fieldInfosFormat().getFieldInfosReader().read(segmentDir, segmentName, ioContext); | |
StoredFieldsReader storedFieldsReader = codec.storedFieldsFormat().fieldsReader(segmentDir, segmentInfos, fieldInfos, ioContext); | |
for (int i = 0; i < segmentInfos.getDocCount(); ++i) { | |
try { | |
DocumentStoredFieldVisitor visitor = new DocumentStoredFieldVisitor(); | |
storedFieldsReader.visitDocument(i, visitor); | |
Document doc = visitor.getDocument(); | |
// do whatever you need with 'doc' | |
System.out.println(doc); | |
} catch (IOException e) { | |
System.err.println("Couldn't get document " + i + ", stored fields corruption?"); | |
e.printStackTrace(System.err); | |
} | |
} |
-use progames?
-(create .fdt .fdx .fnm .frq .nrm .prx .tii .tis and sements_1 .gen)
and web?
-EnglishVietnamese.dict
-EnglishVietnamese.hash
-EnglishVietnamese.index
help me please..
-use progames?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice idea!