I'm using the latest Lucene version 5.4.
I'm curious to know if an Analyzer is stateless and a single instance can be reused by the search application instead of instantiating an Analyzer every time I need it?
I'm currently using the EnglishAnalyzer:
Analyzer analyzer = new EnglishAnalyzer();
Analyzers are not stateless but the reuse of an instance is intended.
Analysers are mainly the factory class for TokenStreams and in particular the EnglishAnalyzer is thread-safe. Solr loads his analysers for each SolrCore only once. So the solr-folk have trust in thread-safety of their analysers.
From the JavaDoc of tokenStream-Method :
Subsequent calls to this method will reuse the previously stored components after resetting them...
Be aware that Analysers implements "Closeable". You can not call tokenStream-Method after the close-Method was called.
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.