O'Reilly logo

Instant Lucene.NET by Michael Heydt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Stopping a slow search (Become an expert)

Searches in Lucene.NET are usually very fast. This is by design with the use of an inverted index model to make lookups highly efficient. But in the case where a complicated search, complex ordering, or having too large an index causes a search to take longer than desired, it is possible to cancel the search.

How to do it…

Searches in Lucene.NET can be canceled by passing an instance of TimeLimitingCollector to the search method of IndexSearcher. The code for the example contains a method named searchWithTimeout in the example's facade that demonstrates the concept. It executes two searches for "morlocks", with the first search having a timeout of 1 ms, and the second having a timeout of 100 ms.

namespace ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required