List of usage examples for org.apache.lucene.index IndexReaderContext reader
public abstract IndexReader reader();
From source file:com.lucene.MyIndexSearcher.java
License:Apache License
public MyIndexSearcher(IndexReaderContext context) { super(context, null); assert context.isTopLevel : "IndexSearcher's ReaderContext must be topLevel for reader" + context.reader(); reader = context.reader();//from w ww . j a v a 2s.com this.readerContext = context; leafContexts = context.leaves(); this.leafSlices = null; }
From source file:lucene.security.search.SecureIndexSearcher.java
License:Apache License
protected IndexReader getSecureIndexReader(IndexReaderContext context) throws IOException { IndexReader indexReader = context.reader(); if (indexReader instanceof DirectoryReader) { return SecureDirectoryReader.create(_accessControlFactory, (DirectoryReader) indexReader, _readAuthorizations, _discoverAuthorizations, _discoverableFields); } else if (indexReader instanceof AtomicReader) { return SecureAtomicReader.create(_accessControlFactory, (AtomicReader) indexReader, _readAuthorizations, _discoverAuthorizations, _discoverableFields); }/*from w w w . ja va2 s . c o m*/ throw new IOException("IndexReader type [" + indexReader.getClass() + "] not supported."); }
From source file:org.apache.solr.search.function.FileFloatSource.java
License:Apache License
@Override public FunctionValues getValues(Map context, AtomicReaderContext readerContext) throws IOException { final int off = readerContext.docBase; IndexReaderContext topLevelContext = ReaderUtil.getTopLevelContext(readerContext); final float[] arr = getCachedFloats(topLevelContext.reader()); return new FloatDocValues(this) { @Override/* w ww . j a v a2s .com*/ public float floatVal(int doc) { return arr[doc + off]; } @Override public Object objectVal(int doc) { return floatVal(doc); // TODO: keep track of missing values } }; }
From source file:org.apache.solr.search.TestIndexSearcher.java
License:Apache License
public void testReopen() throws Exception { assertU(adoc("id", "1", "v_t", "Hello Dude", "v_s1", "string1")); assertU(adoc("id", "2", "v_t", "Hello Yonik", "v_s1", "string2")); assertU(commit());/*from w ww . ja va 2s .c om*/ SolrQueryRequest sr1 = req("q", "foo"); IndexReaderContext rCtx1 = sr1.getSearcher().getTopReaderContext(); String sval1 = getStringVal(sr1, "v_s1", 0); assertEquals("string1", sval1); assertU(adoc("id", "3", "v_s1", "{!literal}")); assertU(adoc("id", "4", "v_s1", "other stuff")); assertU(commit()); SolrQueryRequest sr2 = req("q", "foo"); IndexReaderContext rCtx2 = sr2.getSearcher().getTopReaderContext(); // make sure the readers share the first segment // Didn't work w/ older versions of lucene2.9 going from segment -> multi assertEquals(rCtx1.leaves().get(0).reader(), rCtx2.leaves().get(0).reader()); assertU(adoc("id", "5", "v_f", "3.14159")); assertU(adoc("id", "6", "v_f", "8983", "v_s1", "string6")); assertU(commit()); SolrQueryRequest sr3 = req("q", "foo"); IndexReaderContext rCtx3 = sr3.getSearcher().getTopReaderContext(); // make sure the readers share segments // assertEquals(r1.getLeafReaders()[0], r3.getLeafReaders()[0]); assertEquals(rCtx2.leaves().get(0).reader(), rCtx3.leaves().get(0).reader()); assertEquals(rCtx2.leaves().get(1).reader(), rCtx3.leaves().get(1).reader()); sr1.close(); sr2.close(); // should currently be 1, but this could change depending on future index management int baseRefCount = rCtx3.reader().getRefCount(); assertEquals(1, baseRefCount); assertU(commit()); SolrQueryRequest sr4 = req("q", "foo"); IndexReaderContext rCtx4 = sr4.getSearcher().getTopReaderContext(); // force an index change so the registered searcher won't be the one we are testing (and // then we should be able to test the refCount going all the way to 0 assertU(adoc("id", "7", "v_f", "7574")); assertU(commit()); // test that reader didn't change (according to equals at least... which uses the wrapped reader) assertEquals(rCtx3.reader(), rCtx4.reader()); assertEquals(baseRefCount + 1, rCtx4.reader().getRefCount()); sr3.close(); assertEquals(baseRefCount, rCtx4.reader().getRefCount()); sr4.close(); assertEquals(baseRefCount - 1, rCtx4.reader().getRefCount()); SolrQueryRequest sr5 = req("q", "foo"); IndexReaderContext rCtx5 = sr5.getSearcher().getTopReaderContext(); assertU(delI("1")); assertU(commit()); SolrQueryRequest sr6 = req("q", "foo"); IndexReaderContext rCtx6 = sr6.getSearcher().getTopReaderContext(); assertEquals(1, rCtx6.leaves().get(0).reader().numDocs()); // only a single doc left in the first segment assertTrue(!rCtx5.leaves().get(0).reader().equals(rCtx6.leaves().get(0).reader())); // readers now different sr5.close(); sr6.close(); }
From source file:org.apache.solr.uninverting.FieldCacheSanityChecker.java
License:Apache License
/** * Checks if the seed is an IndexReader, and if so will walk * the hierarchy of subReaders building up a list of the objects * returned by {@code seed.getCoreCacheKey()} *//* ww w .j ava 2 s. c o m*/ private List<Object> getAllDescendantReaderKeys(Object seed) { List<Object> all = new ArrayList<>(17); // will grow as we iter all.add(seed); for (int i = 0; i < all.size(); i++) { final Object obj = all.get(i); // TODO: We don't check closed readers here (as getTopReaderContext // throws AlreadyClosedException), what should we do? Reflection? if (obj instanceof IndexReader) { try { final List<IndexReaderContext> childs = ((IndexReader) obj).getContext().children(); if (childs != null) { // it is composite reader for (final IndexReaderContext ctx : childs) { all.add(ctx.reader().getCoreCacheKey()); } } } catch (AlreadyClosedException ace) { // ignore this reader } } } // need to skip the first, because it was the seed return all.subList(1, all.size()); }