multiReader = new MultiReader(subreaders, true); } catch (IOException ex) { LOGGER.log(Level.SEVERE,
@Override public CacheHelper getReaderCacheHelper() { // MultiReader instances can be short-lived, which would make caching trappy // so we do not cache on them, unless they wrap a single reader in which // case we delegate if (getSequentialSubReaders().size() == 1) { return getSequentialSubReaders().get(0).getReaderCacheHelper(); } return null; }
MultiReader multiReader = null; try { multiReader = new MultiReader(indexReadersArr, false); IndexSearcher allSearcher = new IndexSearcher(multiReader, executorService); return searcherCallback.doWithSearcher(allSearcher); } finally { try { if (multiReader != null) multiReader.close(); } catch (IOException e) { logger.error("Could not close reader", e);
ensureOpen(); MultiReader mr = new MultiReader(newSubReaders); mr.decrefOnClose = newDecrefOnClose; success = true;
public class MultiBufferedReader { public static void main(String[] args) throws IOException { MultiReader mr = new MultiReader(); mr.addListener(new Listener() { @Override public void read(String line) { System.out.println("1: Got " + line); } }); mr.addListener(new Listener() { @Override public void read(String line) { System.out.println("2: Got " + line); } }); mr.read(new File("/etc/hosts")); }
/** * <p>Construct a MultiReader aggregating the named set of (sub)readers. * Directory locking for delete, undeleteAll, and setNorm operations is * left to the subreaders. </p> * @param closeSubReaders indicates whether the subreaders should be closed * when this MultiReader is closed * @param subReaders set of (sub)readers * @throws IOException */ public MultiReader(IndexReader[] subReaders, boolean closeSubReaders) { initialize(subReaders, closeSubReaders); }
rcAr2PgIdxGlobReaders[i] = IndexReader.open(rcAr2PgIdxGlobLDirs[i], false); // Read-only = false MultiReader rcAr2PgIdxMultiReader = new MultiReader(rcAr2PgIdxGlobReaders); IndexSearcher rcAr2PgIdxSearcher = new IndexSearcher(rcAr2PgIdxMultiReader); rcAr2ObjIdxGlobReaders[i] = IndexReader.open(rcAr2ObjIdxGlobLDirs[i], false); // Read-only = false MultiReader rcAr2ObjIdxMultiReader = new MultiReader(rcAr2ObjIdxGlobReaders); IndexSearcher rcAr2ObjIdxSearcher = new IndexSearcher(rcAr2ObjIdxMultiReader); rcAr2PgIdxMultiReader.close(); rcAr2PgIdxSearcher.close(); rcAr2ObjIdxMultiReader.close(); rcAr2ObjIdxSearcher.close();
ensureOpen(); MultiReader mr = new MultiReader(newSubReaders); mr.decrefOnClose = newDecrefOnClose; success = true;
/** * <p>Construct a MultiReader aggregating the named set of (sub)readers. * Directory locking for delete, undeleteAll, and setNorm operations is * left to the subreaders. </p> * <p>Note that all subreaders are closed if this Multireader is closed.</p> * @param subReaders set of (sub)readers * @throws IOException */ public MultiReader(IndexReader[] subReaders) { initialize(subReaders, true); }
private IndexHits<Document> search( IndexReference searcherRef, IndexSearcher fulltextTransactionStateSearcher, Query query, QueryContext additionalParametersOrNull, Collection<EntityId> removed ) throws IOException { if ( fulltextTransactionStateSearcher != null && !removed.isEmpty() ) { letThroughAdditions( fulltextTransactionStateSearcher, query, removed ); } IndexSearcher searcher = fulltextTransactionStateSearcher == null ? searcherRef.getSearcher() : new IndexSearcher( new MultiReader( searcherRef.getSearcher().getIndexReader(), fulltextTransactionStateSearcher.getIndexReader() ) ); IndexHits<Document> result; if ( additionalParametersOrNull != null && additionalParametersOrNull.getTop() > 0 ) { result = new TopDocsIterator( query, additionalParametersOrNull, searcher ); } else { Sort sorting = additionalParametersOrNull != null ? additionalParametersOrNull.getSorting() : null; boolean forceScore = additionalParametersOrNull == null || !additionalParametersOrNull.getTradeCorrectnessForSpeed(); DocValuesCollector collector = new DocValuesCollector( forceScore ); searcher.search( query, collector ); return collector.getIndexHits( sorting ); } return result; }
final IndexReader ir2 = writer2.getReader(); final MultiReader mr = new MultiReader(ir1, ir2); final IndexSearcher searcher = newSearcher(mr); final FuzzyQuery fq = new FuzzyQuery(new Term(DEFAULT_TEST_FIELD, "z123456"), 1, 0, 2, false); assertEquals(5, docs.totalHits); // 5 docs, from the a and b's mr.close(); ir2.close(); writer2.close();
@Override protected synchronized void doClose() throws IOException { IOException ioe = null; for (final IndexReader r : getSequentialSubReaders()) { try { if (closeSubReaders) { r.close(); } else { r.decRef(); } } catch (IOException e) { if (ioe == null) ioe = e; } } // throw the first exception if (ioe != null) throw ioe; } }
/** Construct reading the named set of readers. */ MultiReader(Directory directory, SegmentInfos sis, boolean closeDirectory, IndexReader[] subReaders) throws IOException { super(directory, sis, closeDirectory); initialize(subReaders); }
public MultiReader mergeIndexReaders(List<ZoieIndexReader<T>> readerList) { MultiReader r = new MultiReader(readerList.toArray(new IndexReader[readerList.size()]),false); return r; } }
final IndexReader ir2 = writer2.getReader(); final MultiReader mr = new MultiReader(ir1, ir2); final IndexSearcher searcher = newSearcher(mr); final FuzzyQuery fq = new FuzzyQuery(new Term(DEFAULT_TEST_FIELD, "z123456"), 1, 0, 2, false); assertEquals(5, docs.totalHits); // 5 docs, from the a and b's mr.close(); ir2.close(); writer2.close();
@Override public CacheHelper getReaderCacheHelper() { // MultiReader instances can be short-lived, which would make caching trappy // so we do not cache on them, unless they wrap a single reader in which // case we delegate if (getSequentialSubReaders().size() == 1) { return getSequentialSubReaders().get(0).getReaderCacheHelper(); } return null; }
/** * <p>Construct a MultiReader aggregating the named set of (sub)readers. * Directory locking for delete, undeleteAll, and setNorm operations is * left to the subreaders. </p> * @param closeSubReaders indicates whether the subreaders should be closed * when this MultiReader is closed * @param subReaders set of (sub)readers * @throws IOException */ public MultiReader(IndexReader[] subReaders, boolean closeSubReaders) { initialize(subReaders, closeSubReaders); }
private void reloadSearch() { //ok load all index to searcher if (readerList.size() > 0) { try { DirectoryReader[] dictList = readerList.values().toArray(new DirectoryReader[readerList.size()]); this.allInOneReader = new MultiReader(dictList); searcher = new IndexSearcher(this.allInOneReader); } catch (Exception e) { e.printStackTrace(); } } }
@Override protected synchronized void doClose() throws IOException { IOException ioe = null; for (final IndexReader r : getSequentialSubReaders()) { try { if (closeSubReaders) { r.close(); } else { r.decRef(); } } catch (IOException e) { if (ioe == null) ioe = e; } } // throw the first exception if (ioe != null) throw ioe; } }
/** * <p>Construct a MultiReader aggregating the named set of (sub)readers. * Directory locking for delete, undeleteAll, and setNorm operations is * left to the subreaders. </p> * <p>Note that all subreaders are closed if this Multireader is closed.</p> * @param subReaders set of (sub)readers * @throws IOException */ public MultiReader(IndexReader[] subReaders) { initialize(subReaders, true); }