Skip to content

Instantly share code, notes, and snippets.

@JeffreyZhao
Created September 30, 2009 14:22
Show Gist options
  • Save JeffreyZhao/198131 to your computer and use it in GitHub Desktop.
Save JeffreyZhao/198131 to your computer and use it in GitHub Desktop.
private static RAMDirectory IndexBenchmark(String target, int topN) throws Exception {
System.gc();
if (topN < 0) topN = Integer.MAX_VALUE;
RAMDirectory ramDir = new RAMDirectory();
IndexWriter ramWriter = new IndexWriter(ramDir, new StandardAnalyzer());
FileInputStream fstream = new FileInputStream("Content.txt");
BufferedReader reader = new BufferedReader(new InputStreamReader(fstream));
StringBuffer sb = null;
String filePath = null;
int number = 0;
Stopwatch watch = new Stopwatch();
watch.start();
while (true)
{
String line = reader.readLine();
if (line == null) break;
if (sb == null)
{
filePath = line;
sb = new StringBuffer();
}
else if (line.equals(separator))
{
// Document doc = new Document();
// doc.add(new Field("File", filePath, Field.Store.YES, Field.Index.NO));
// doc.add(new Field("Content", sb.toString(), Field.Store.NO, Field.Index.ANALYZED));
// ramWriter.addDocument(doc);
if (number++ > topN) break;
if (number % 1000 == 0)
{
System.out.println(number + " " + watch.getElapsedMilliseconds());
}
filePath = null;
sb = null;
}
else
{
sb.append(line);
}
}
watch.stop();
System.out.println("Finished " + watch.getElapsedMilliseconds());
ramWriter.close();
return ramDir;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment