use of org.apache.lucene.search.SearcherManager in project OpenGrok by OpenGrok.
the class RuntimeEnvironment method getIndexSearcher.
/**
* Get IndexSearcher for given project.
* Each IndexSearcher is born from a SearcherManager object. There is one SearcherManager for every project.
* This schema makes it possible to reuse IndexSearcher/IndexReader objects so the heavy lifting
* (esp. system calls) performed in FSDirectory and DirectoryReader happens only once for a project.
* The caller has to make sure that the IndexSearcher is returned back
* to the SearcherManager. This is done with returnIndexSearcher().
* The return of the IndexSearcher should happen only after the search result data are read fully.
*
* @param projectName project
* @return SearcherManager for given project
* @throws IOException I/O exception
*/
@SuppressWarnings("java:S2095")
public SuperIndexSearcher getIndexSearcher(String projectName) throws IOException {
SearcherManager mgr = searcherManagerMap.get(projectName);
SuperIndexSearcher searcher;
if (mgr == null) {
File indexDir = new File(getDataRootPath(), IndexDatabase.INDEX_DIR);
Directory dir = FSDirectory.open(new File(indexDir, projectName).toPath());
mgr = new SearcherManager(dir, new ThreadpoolSearcherFactory());
searcherManagerMap.put(projectName, mgr);
}
searcher = (SuperIndexSearcher) mgr.acquire();
searcher.setSearcherManager(mgr);
return searcher;
}
Aggregations