简体   繁体   中英

Lucene: What is the correct way to cancel a search?

I am currently looking into lucene and wondered what is the best way to cancel a search that is performed with the org.apache.lucene.search.IndexSearcher ?

I can imagine to simply call interrupt on the thread that i created for the search, but i'm not sure if the relevant components inside lucene react on interruption (without searching thru the depths of the source code).

Is there an 'official' way / what would be the best way?

Best regards

IndexSearcher provides a constructor with an ExecutorService (follow the link in constructor for an example usage) as parameter. This can be used to terminate the search. However, note the remark on the use of NIOFSDirectory .

See https://lucene.apache.org/core/6_0_0/core/org/apache/lucene/search/IndexSearcher.html

And https://issues.apache.org/jira/browse/LUCENE-2239

Extract from the JavaDocs and issue ticket: It's important to not call shutdownNow() (interrupt the threads) when the default channel-based FSDirectory implementations are used. The use of the (slower) RAFDirectory seems to have no problem with the resulting interrupted threads.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM