@Override public BulkScorer bulkScorer(LeafReaderContext context) throws IOException { if (used.compareAndSet(false, true)) { policy.onUse(getQuery()); } DocIdSet docIdSet = get(in.getQuery(), context); if (docIdSet == null) { if (shouldCache(context)) { docIdSet = cache(context); putIfAbsent(in.getQuery(), context, docIdSet); } else { return in.bulkScorer(context); } } assert docIdSet != null; if (docIdSet == DocIdSet.EMPTY) { return null; } final DocIdSetIterator disi = docIdSet.iterator(); if (disi == null) { return null; } return new DefaultBulkScorer(new ConstantScoreScorer(this, 0f, disi)); }
CachingWrapperWeight(Weight in, QueryCachingPolicy policy) { super(in.getQuery()); this.in = in; this.policy = policy; used = new AtomicBoolean(false); }
private boolean shouldCache(LeafReaderContext context) throws IOException { return cacheEntryHasReasonableWorstCaseSize( ReaderUtil.getTopLevelContext(context).reader().maxDoc()) && policy.shouldCache(in.getQuery(), context); }
@Override public Query getQuery() { return w.getQuery(); }