public class TimeLimitingCollector extends Collector
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
.Modifier and Type | Class and Description |
---|---|
static class |
TimeLimitingCollector.TimeExceededException
Thrown when elapsed search time exceeds allowed search time.
|
static class |
TimeLimitingCollector.TimerThread
Thread used to timeout search requests.
|
Constructor and Description |
---|
TimeLimitingCollector(Collector collector,
Counter clock,
long ticksAllowed)
Create a TimeLimitedCollector wrapper over another
Collector with a specified timeout. |
Modifier and Type | Method and Description |
---|---|
boolean |
acceptsDocsOutOfOrder()
Return
true if this collector does not
require the matching docIDs to be delivered in int sort
order (smallest to largest) to Collector.collect(int) . |
void |
collect(int doc)
Calls
Collector.collect(int) on the decorated Collector
unless the allowed time has passed, in which case it throws an exception. |
static Counter |
getGlobalCounter()
Returns the global TimerThreads
Counter |
static TimeLimitingCollector.TimerThread |
getGlobalTimerThread()
Returns the global
TimeLimitingCollector.TimerThread . |
boolean |
isGreedy()
Checks if this time limited collector is greedy in collecting the last hit.
|
void |
setBaseline()
Syntactic sugar for
setBaseline(long) using Counter.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.
|
void |
setNextReader(AtomicReaderContext context)
Called before collecting from each
AtomicReaderContext . |
void |
setScorer(Scorer scorer)
Called before successive calls to
Collector.collect(int) . |
public TimeLimitingCollector(Collector collector, Counter clock, long ticksAllowed)
Collector
with a specified timeout.collector
- the wrapped Collector
clock
- the timer clockticksAllowed
- max time allowed for collecting
hits after which TimeLimitingCollector.TimeExceededException
is thrownpublic void setBaseline(long clockTime)
Example usage:
Counter clock = ...; long baseline = clock.get(); // ... prepare search TimeLimitingCollector collector = new TimeLimitingCollector(c, clock, numTicks); collector.setBaseline(baseline); indexSearcher.search(query, collector);
setBaseline()
public void setBaseline()
setBaseline(long)
using Counter.get()
on the clock passed to the constructor.public boolean isGreedy()
TimeLimitingCollector.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 a TimeLimitingCollector.TimeExceededException
.setGreedy(boolean)
public void setGreedy(boolean greedy)
greedy
- true to make this time limited greedyisGreedy()
public void collect(int doc) throws IOException
Collector.collect(int)
on the decorated Collector
unless the allowed time has passed, in which case it throws an exception.collect
in class Collector
TimeLimitingCollector.TimeExceededException
- if the time allowed has exceeded.IOException
public void setNextReader(AtomicReaderContext context) throws IOException
Collector
AtomicReaderContext
. All doc ids in
Collector.collect(int)
will correspond to IndexReaderContext.reader()
.
Add AtomicReaderContext.docBase
to the current IndexReaderContext.reader()
's
internal document id to re-base ids in Collector.collect(int)
.setNextReader
in class Collector
context
- next atomic reader contextIOException
public void setScorer(Scorer scorer) throws IOException
Collector
Collector.collect(int)
. Implementations
that need the score of the current document (passed-in to
Collector.collect(int)
), should save the passed-in Scorer and call
scorer.score() when needed.setScorer
in class Collector
IOException
public boolean acceptsDocsOutOfOrder()
Collector
true
if this collector does not
require the matching docIDs to be delivered in int sort
order (smallest to largest) to Collector.collect(int)
.
Most Lucene Query implementations will visit
matching docIDs in order. However, some queries
(currently limited to certain cases of BooleanQuery
) can achieve faster searching if the
Collector
allows them to deliver the
docIDs out of order.
Many collectors don't mind getting docIDs out of
order, so it's important to return true
here.
acceptsDocsOutOfOrder
in class Collector
public void setCollector(Collector collector)
collector
- The actual collector performing search functionalitypublic static Counter getGlobalCounter()
Counter
Invoking this creates may create a new instance of TimeLimitingCollector.TimerThread
iff
the global TimeLimitingCollector.TimerThread
has never been accessed before. The thread
returned from this method is started on creation and will be alive unless
you stop the TimeLimitingCollector.TimerThread
via TimeLimitingCollector.TimerThread.stopTimer()
.
Counter
public static TimeLimitingCollector.TimerThread getGlobalTimerThread()
TimeLimitingCollector.TimerThread
.
Invoking this creates may create a new instance of TimeLimitingCollector.TimerThread
iff
the global TimeLimitingCollector.TimerThread
has never been accessed before. The thread
returned from this method is started on creation and will be alive unless
you stop the TimeLimitingCollector.TimerThread
via TimeLimitingCollector.TimerThread.stopTimer()
.
TimeLimitingCollector.TimerThread
Copyright © 2000-2013 Apache Software Foundation. All Rights Reserved.