Skip to content

Instantly share code, notes, and snippets.

@shriphani
Last active December 18, 2015 08:39
Show Gist options
  • Save shriphani/5755421 to your computer and use it in GitHub Desktop.
Save shriphani/5755421 to your computer and use it in GitHub Desktop.
import java.io.File;
import java.io.IOException;
import org.apache.lucene.codecs.*;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.*;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.BytesRef;
public class IndexReaderTest {
public static void main (String ... args) {
try{
IndexReader ir = DirectoryReader.open(FSDirectory.open(new File("/Users/shriphani/Documents/Summer2013/lucene-4.3.0/index")));
// Number of Documents in the index directory
System.out.println(ir.numDocs());
// List all the terms, their TFs and DFs
AtomicReader ar = SlowCompositeReaderWrapper.wrap(ir);
for (String field : ar.fields()) {
System.out.println(field);
Terms ts = ar.fields().terms(field);
TermsEnum tes = ts.iterator(null);
BytesRef text;
while ((text = tes.next()) != null) {
System.out.print("field=" + field + "; text=" + text.utf8ToString() + "; tf= ");
DocsEnum de = ar.termDocsEnum(new Term(field, text));
System.out.println(de.nextDoc());
System.out.println(de.nextDoc());
System.out.println(de.nextDoc());
}
}
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment