private Collector getInsanityWrapper(final String field, Collector collector) { SchemaField sf = searcher.getSchema().getFieldOrNull(field); if (sf != null && !sf.hasDocValues() && !sf.multiValued() && sf.getType().getNumberType() != null) { // it's a single-valued numeric field: we must currently create insanity :( // there isn't a GroupedFacetCollector that works on numerics right now... return new FilterCollector(collector) { @Override public LeafCollector getLeafCollector(LeafReaderContext context) throws IOException { LeafReader insane = Insanity.wrapInsanity(context.reader(), field); return in.getLeafCollector(insane.getContext()); } }; } else { return collector; } }
@Override public LeafCollector getLeafCollector(LeafReaderContext context) throws IOException { return new LeafCollector() { // ignore scorer public void setScorer(Scorer scorer) throws IOException { } public void collect(int doc) throws IOException { Document document = searcher.doc(doc, field); String fieldValue = document.get(fieldName); addData(fieldValue); } }; }
@Override public LeafCollector getLeafCollector(LeafReaderContext context) throws IOException { if (cancelled.get()) { throw new TaskCancelledException("cancelled"); } if (leafLevel) { return new CancellableLeafCollector(super.getLeafCollector(context)); } else { return super.getLeafCollector(context); } }
@Override public LeafCollector getLeafCollector(LeafReaderContext context) throws IOException { final Scorer filterScorer = filter.scorer(context); final LeafCollector in = collector.getLeafCollector(context); final Bits bits = Lucene.asSequentialAccessBits(context.reader().maxDoc(), filterScorer); return new FilterLeafCollector(in) { @Override public void collect(int doc) throws IOException { if (bits.get(doc)) { in.collect(doc); } } }; }
public void testLowLevelCancellableCollector() throws IOException { TotalHitCountCollector collector = new TotalHitCountCollector(); AtomicBoolean cancelled = new AtomicBoolean(); CancellableCollector cancellableCollector = new CancellableCollector(cancelled::get, true, collector); final LeafCollector leafCollector = cancellableCollector.getLeafCollector(reader.leaves().get(0)); leafCollector.collect(0); cancelled.set(true); expectThrows(TaskCancelledException.class, () -> leafCollector.collect(1)); }
public void testCancellableCollector() throws IOException { TotalHitCountCollector collector = new TotalHitCountCollector(); AtomicBoolean cancelled = new AtomicBoolean(); CancellableCollector cancellableCollector = new CancellableCollector(cancelled::get, false, collector); final LeafCollector leafCollector = cancellableCollector.getLeafCollector(reader.leaves().get(0)); leafCollector.collect(0); cancelled.set(true); leafCollector.collect(1); expectThrows(TaskCancelledException.class, () -> cancellableCollector.getLeafCollector(reader.leaves().get(1))); }
public void testCollector() throws IOException { TotalHitCountCollector collector = new TotalHitCountCollector(); ProfileCollector profileCollector = new ProfileCollector(collector); assertEquals(0, profileCollector.getTime()); final LeafCollector leafCollector = profileCollector.getLeafCollector(reader.leaves().get(0)); assertThat(profileCollector.getTime(), greaterThan(0L)); long time = profileCollector.getTime(); leafCollector.setScorer(null); assertThat(profileCollector.getTime(), greaterThan(time)); time = profileCollector.getTime(); leafCollector.collect(0); assertThat(profileCollector.getTime(), greaterThan(time)); }
@Override public LeafCollector getLeafCollector(LeafReaderContext context) throws IOException { final SortedDocValues values = globalIfd.load(context).getOrdinalsValues(parentType); if (values == null) { throw new CollectionTerminatedException(); } return new LeafCollector() { Scorer scorer; @Override public void setScorer(Scorer scorer) throws IOException { this.scorer = scorer; } @Override public void collect(int doc) throws IOException { long globalOrdinal = values.getOrd(doc); if (globalOrdinal != SortedSetDocValues.NO_MORE_ORDS) { long parentIdx = parentIdxs.add(globalOrdinal); if (parentIdx >= 0) { scores = bigArrays.grow(scores, parentIdx + 1); scores.set(parentIdx, scorer.score()); } else { assert false : "parent id should only match once, since there can only be one parent doc"; } } } }; }
private CancellableLeafCollector(LeafCollector in) { super(in); }
@Override public LeafCollector getLeafCollector(LeafReaderContext context) throws IOException { return collector.getLeafCollector(context); }
@Override public LeafCollector getLeafCollector( LeafReaderContext paramLeafReaderContext) throws IOException { return this; }