Counter can either be thread safe or not - just use the static Counter.newCounter(boolean threadSafe)
method to instantiate one that fits you.
Then, let's say we allow 10 ticks and we update ticks in a separate thread. Code should look like this:
Counter clock = Counter.newCounter(true); TimeLimitingCollector collector = new TimeLimitingCollector(c, clock, 10); collector.setBaseline(0); new Thread() { public void run() { clock.addAndGet(1); // will kill the indexSearcher.search(...) after 10 ticks (10 seconds) Thread.sleep(1000); // try-catch is necessary here, yes } }.start(); indexSearcher.search(query, collector);
I, however, find the above a bit cumbersome. Guava's TimeLimiter.callWithTimeout(...) looks much cleaner even though not native to Lucene.
Read full article from performance - TimeLimitingCollector Lucene, how to use effectively? - Stack Overflow
No comments:
Post a Comment