benchLucene Blog
Status: Beta
Brought to you by:
dovestech
public static double bench(String dir, String field)
{
double queryLength = 0;
String search = UUID.randomUUID().toString();
double startQuery = System.currentTimeMillis();
try
{
File file = new File(dir);
FSDirectory directory = FSDirectory.open(file);
IndexSearcher isearcher = new IndexSearcher(directory, true);
Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_31);
ScoreDoc[] hits;
MultiFieldQueryParser parser = new MultiFieldQueryParser(Version.LUCENE_31, new String[] {field}, analyzer);
Query query = parser.parse(search);
hits = isearcher.search(query, 2000000).scoreDocs;
queryLength = System.currentTimeMillis() - startQuery;
queryLength = queryLength / 1000;
isearcher.close();
directory.close();
}
catch (Exception e)
{
System.err.println(e);
}
return queryLength;
}