Class TimeLimitingCollector
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.
Implements
Inherited Members
Namespace: Lucene.Net.Search
Assembly: Lucene.Net.dll
Syntax
public class TimeLimitingCollector : ICollector
Constructors
TimeLimitingCollector(ICollector, Counter, long)
Create a TimeLimitingCollector wrapper over another ICollector with a specified timeout.
Declaration
public TimeLimitingCollector(ICollector collector, Counter clock, long ticksAllowed)
Parameters
Type | Name | Description |
---|---|---|
ICollector | collector | The wrapped ICollector |
Counter | clock | The timer clock |
long | ticksAllowed | Max time allowed for collecting hits after which TimeLimitingCollector.TimeExceededException is thrown |
Properties
AcceptsDocsOutOfOrder
Return true
if this collector does not
require the matching docIDs to be delivered in int sort
order (smallest to largest) to 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 ICollector 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.
Declaration
public virtual bool AcceptsDocsOutOfOrder { get; }
Property Value
Type | Description |
---|---|
bool |
GlobalCounter
Returns the global TimeLimitingCollector.TimerThread's 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 StopTimer().
Note
This API is experimental and might change in incompatible ways in the next release.
Declaration
public static Counter GlobalCounter { get; }
Property Value
Type | Description |
---|---|
Counter | the global TimerThreads Counter |
GlobalTimerThread
Returns the global 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 StopTimer().
Note
This API is experimental and might change in incompatible ways in the next release.
Declaration
public static TimeLimitingCollector.TimerThread GlobalTimerThread { get; }
Property Value
Type | Description |
---|---|
TimeLimitingCollector.TimerThread | the global TimeLimitingCollector.TimerThread |
IsGreedy
Checks if this time limited collector is greedy in collecting the last hit. A non greedy collector, upon a timeout, would throw a 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.
Declaration
public virtual bool IsGreedy { get; set; }
Property Value
Type | Description |
---|---|
bool |
Methods
Collect(int)
Calls Collect(int) on the decorated ICollector unless the allowed time has passed, in which case it throws an exception.
Declaration
public virtual void Collect(int doc)
Parameters
Type | Name | Description |
---|---|---|
int | doc |
Exceptions
Type | Condition |
---|---|
TimeLimitingCollector.TimeExceededException | If the time allowed has exceeded. |
SetBaseline()
Syntactic sugar for SetBaseline(long) using Value on the clock passed to the constructor.
Declaration
public virtual void SetBaseline()
SetBaseline(long)
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 is in the Lucene.Net.Util namespace
Counter clock = Counter.NewCounter(true);
long baseline = clock.Get();
// ... prepare search
TimeLimitingCollector collector = new TimeLimitingCollector(c, clock, numTicks);
collector.SetBaseline(baseline);
indexSearcher.Search(query, collector);
Declaration
public virtual void SetBaseline(long clockTime)
Parameters
Type | Name | Description |
---|---|---|
long | clockTime |
See Also
SetCollector(ICollector)
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.
Declaration
public virtual void SetCollector(ICollector collector)
Parameters
Type | Name | Description |
---|---|---|
ICollector | collector | The actual collector performing search functionality. |
SetNextReader(AtomicReaderContext)
Called before collecting from each AtomicReaderContext. All doc ids in Collect(int) will correspond to Reader.
Add DocBase to the current Reader's internal document id to re-base ids in Collect(int).Declaration
public virtual void SetNextReader(AtomicReaderContext context)
Parameters
Type | Name | Description |
---|---|---|
AtomicReaderContext | context | next atomic reader context |
SetScorer(Scorer)
Called before successive calls to Collect(int). Implementations
that need the score of the current document (passed-in to
Collect(int)), should save the passed-in Scorer and call
scorer.GetScore()
when needed.
Declaration
public virtual void SetScorer(Scorer scorer)
Parameters
Type | Name | Description |
---|---|---|
Scorer | scorer |