public void addSearcher(File luceneDir) { if (isClosed.get()) return; final Searcher searcher = SearcherFactory.getSearcher(luceneDir, searcherType); try { searcher.open(); this.clusterSearchers.add(searcher); this.searchers.clear(); this.searchers.addAll(clusterSearchers); if (extraSearchers != null) this.searchers.addAll(extraSearchers); } catch (FileNotFoundException fnfe) { // this means we didn't add anything to an index, which happens i.e. if we didn't have any // asian (or non-asian) posts in a batch. // so what we'll do is log it and ignore this index. System.err.println(new Date() + ": WARNING : Ignoring empty index at '" + luceneDir + "'!"); } catch (IOException e) { System.err.println( new Date() + ": *** ERROR! " + luceneId + " can't open lucene searcher at '" + luceneDir + "'"); e.printStackTrace(System.err); } }
/** * Expert: creates a searcher from the provided {@link IndexReader} using the provided {@link * SearcherFactory}. NOTE: this decRefs incoming reader on throwing an exception. */ public static IndexSearcher getSearcher( SearcherFactory searcherFactory, IndexReader reader, IndexReader previousReader) throws IOException { boolean success = false; final IndexSearcher searcher; try { searcher = searcherFactory.newSearcher(reader, previousReader); if (searcher.getIndexReader() != reader) { throw new IllegalStateException( "SearcherFactory must wrap exactly the provided reader (got " + searcher.getIndexReader() + " but expected " + reader + ")"); } success = true; } finally { if (!success) { reader.decRef(); } } return searcher; }
@Override public boolean start() { mSearcher = SearcherFactory.createSearcher(); SearcherKit.init(mSearcher); return true; }