Package org.apache.lucene.search
Class TimeLimitingCollector
java.lang.Object
org.apache.lucene.search.TimeLimitingCollector
- All Implemented Interfaces:
Collector
The
TimeLimitingCollector
is used to timeout search requests that take longer than the
maximum allowed search time limit. After this time is exceeded, the search thread is stopped by
throwing a TimeLimitingCollector.TimeExceededException
.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Thrown when elapsed search time exceeds allowed search time.static final class
Thread used to timeout search requests. -
Constructor Summary
ConstructorsConstructorDescriptionTimeLimitingCollector
(Collector collector, Counter clock, long ticksAllowed) Create a TimeLimitedCollector wrapper over anotherCollector
with a specified timeout. -
Method Summary
Modifier and TypeMethodDescriptionstatic Counter
Returns the global TimerThreadsCounter
Returns the globalTimeLimitingCollector.TimerThread
.getLeafCollector
(LeafReaderContext context) Create a newcollector
to collect the given context.boolean
isGreedy()
Checks if this time limited collector is greedy in collecting the last hit.Indicates what features are required from the scorer.void
Syntactic sugar forsetBaseline(long)
usingCounter.get()
on the clock passed to the constructor.void
setBaseline
(long clockTime) Sets the baseline for this collector.void
setCollector
(Collector collector) This is so the same timer can be used with a multi-phase search process such as grouping.void
setGreedy
(boolean greedy) Sets whether this time limited collector is greedy.
-
Constructor Details
-
TimeLimitingCollector
Create a TimeLimitedCollector wrapper over anotherCollector
with a specified timeout.- Parameters:
collector
- the wrappedCollector
clock
- the timer clockticksAllowed
- max time allowed for collecting hits after whichTimeLimitingCollector.TimeExceededException
is thrown
-
-
Method Details
-
setBaseline
public void setBaseline(long clockTime) Sets the baseline for this collector. By default the collectors baseline is initialized once the first reader is passed to the collector. To include operations executed in prior to the actual document collection set the baseline through this method in your prelude.Example usage:
Counter clock = ...; long baseline = clock.get(); // ... prepare search TimeLimitingCollector collector = new TimeLimitingCollector(c, clock, numTicks); collector.setBaseline(baseline); indexSearcher.search(query, collector);
- See Also:
-
setBaseline
public void setBaseline()Syntactic sugar forsetBaseline(long)
usingCounter.get()
on the clock passed to the constructor. -
isGreedy
public boolean isGreedy()Checks if this time limited collector is greedy in collecting the last hit. A non greedy collector, upon a timeout, would throw aTimeLimitingCollector.TimeExceededException
without allowing the wrapped collector to collect current doc. A greedy one would first allow the wrapped hit collector to collect current doc and only then throw aTimeLimitingCollector.TimeExceededException
. However, if the timeout is detected ingetLeafCollector(org.apache.lucene.index.LeafReaderContext)
then no current document is collected.- See Also:
-
setGreedy
public void setGreedy(boolean greedy) Sets whether this time limited collector is greedy.- Parameters:
greedy
- true to make this time limited greedy- See Also:
-
getLeafCollector
Description copied from interface:Collector
Create a newcollector
to collect the given context.- Specified by:
getLeafCollector
in interfaceCollector
- Parameters:
context
- next atomic reader context- Throws:
IOException
-
scoreMode
Description copied from interface:Collector
Indicates what features are required from the scorer. -
setCollector
This is so the same timer can be used with a multi-phase search process such as grouping. We don't want to create a new TimeLimitingCollector for each phase because that would reset the timer for each phase. Once time is up subsequent phases need to timeout quickly.- Parameters:
collector
- The actual collector performing search functionality
-
getGlobalCounter
Returns the global TimerThreadsCounter
Invoking this creates may create a new instance of
TimeLimitingCollector.TimerThread
iff the globalTimeLimitingCollector.TimerThread
has never been accessed before. The thread returned from this method is started on creation and will be alive unless you stop theTimeLimitingCollector.TimerThread
viaTimeLimitingCollector.TimerThread.stopTimer()
.- Returns:
- the global TimerThreads
Counter
- WARNING: This API is experimental and might change in incompatible ways in the next release.
-
getGlobalTimerThread
Returns the globalTimeLimitingCollector.TimerThread
.Invoking this creates may create a new instance of
TimeLimitingCollector.TimerThread
iff the globalTimeLimitingCollector.TimerThread
has never been accessed before. The thread returned from this method is started on creation and will be alive unless you stop theTimeLimitingCollector.TimerThread
viaTimeLimitingCollector.TimerThread.stopTimer()
.- Returns:
- the global
TimeLimitingCollector.TimerThread
- WARNING: This API is experimental and might change in incompatible ways in the next release.
-