## org.apache.lucene.search
Class TimeLimitedCollector

    java.lang.Object
      org.apache.lucene.search.HitCollector
          org.apache.lucene.search.TimeLimitedCollector

    public class TimeLimitedCollector

extends HitCollector

The TimeLimitedCollector 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 TimeExceeded Exception.

Nested Class Summary
`static class` `TimeLimitedCollector.TimeExceededException` Thrown when elapsed search time exceeds allowed search time.

Field Summary
`boolean` `DEFAULT_GREEDY` Default for `isGreedy()`.
`static int` `DEFAULT_RESOLUTION` Default timer resolution.

Constructor Summary
`TimeLimitedCollector(HitCollector hc, long timeAllowed)` Create a TimeLimitedCollector wrapper over another HitCollector with a specified timeout.

Method Summary
`void` `collect(int doc, float score)` Calls collect() on the decorated HitCollector.
`static long` `getResolution()` Return the timer resolution.
`boolean` `isGreedy()` Checks if this time limited collector is greedy in collecting the last hit.
`void` `setGreedy(boolean greedy)` Sets whether this time limited collector is greedy.
`static void` `setResolution(long newResolution)` Set the timer resolution.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### DEFAULT_RESOLUTION

    public static final int DEFAULT_RESOLUTION

  Default timer resolution.

  See Also:
    `setResolution(long)`, Constant Field Values

### DEFAULT_GREEDY

    public boolean DEFAULT_GREEDY

  Default for `isGreedy()`.

  See Also:
    `isGreedy()`

Constructor Detail

### TimeLimitedCollector

    public TimeLimitedCollector(HitCollector hc,
                                long timeAllowed)

  Create a TimeLimitedCollector wrapper over another HitCollector with a specified timeout.

  Parameters:
    `hc` - the wrapped HitCollector
    `timeAllowed` - max time allowed for collecting hits after which `TimeLimitedCollector.TimeExceededException` is thrown

Method Detail

### collect

    public void collect(int doc,
                        float score)

  Calls collect() on the decorated HitCollector.

  Specified by:
    `collect` in class `HitCollector`
  Throws:
    `TimeLimitedCollector.TimeExceededException` - if the time allowed has been exceeded.

### getResolution

    public static long getResolution()

  Return the timer resolution.

  See Also:
    `setResolution(long)`

### setResolution

    public static void setResolution(long newResolution)

  Set the timer resolution. The default timer resolution is 20 milliseconds. This means that a search required to take no longer than 800 milliseconds may be stopped after 780 to 820 milliseconds.
  Note that:
  - Finer (smaller) resolution is more accurate but less efficient.
  - Setting resolution to less than 5 milliseconds will be silently modified to 5 milliseconds.
  - Setting resolution smaller than current resolution might take effect only after current resolution. (Assume current resolution of 20 milliseconds is modified to 5 milliseconds, then it can take up to 20 milliseconds for the change to have effect.

### 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 a `TimeLimitedCollector.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 `TimeLimitedCollector.TimeExceededException`.

  See Also:
    `setGreedy(boolean)`

### 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:
    `isGreedy()`

Copyright © 2000-2009 Apache Software Foundation. All Rights Reserved.