How can i get the exact time taken by lucene to search a string.
I wanted to show something like this :
About x
results in xx
seconds.
how can i get exact time ? is their any utility under lucene library for this ? or do i need to calculate this on my own ?
EDIT : assuming their is no utility for this under lucene core library :
this is a search code :
TopScoreDocCollector collector = TopScoreDocCollector.create(100, true);
is.search(query, collector);
hits = collector.topDocs().scoreDocs;
how can i get exact time of search (which line should i wrap with timer) ?
one more edit : I tried This :
long t1 = System.currentTimeMillis();
is.search(query, collector);
hits = collector.topDocs().scoreDocs;
long t2 = System.currentTimeMillis();
Long time = (t2-t1);
System.out.println("time : " + time);
I am getting time : 0
on console for every search.
does that mean... Lucene is taking no time in search ? (i have only 100 documents in my index)
And one more : tried this ;
long start = System.nanoTime();
is.search(query, collector);
hits = collector.topDocs().scoreDocs;
long end = System.nanoTime();
long time = (end - start) / 1000;
this prints :
time : 10261
time : 12285
time : 14513
time : 1309
System.nanoTime()
– mishadoff