@Override protected boolean match(int doc) { if (parentWeight.remaining == 0) { throw new CollectionTerminatedException(); } final long parentOrd = ordinals.getOrd(doc); if (parentOrd >= 0) { final long parentIdx = parentIds.find(parentOrd); if (parentIdx != -1) { parentWeight.remaining--; int count = occurrences.get(parentIdx); if (count >= minChildren && count <= maxChildren) { return true; } } } return false; }
private static void suggest(IndexSearcher searcher, CompletionQuery query, TopSuggestDocsCollector collector) throws IOException { query = (CompletionQuery) query.rewrite(searcher.getIndexReader()); Weight weight = query.createWeight(searcher, collector.needsScores()); for (LeafReaderContext context : searcher.getIndexReader().leaves()) { BulkScorer scorer = weight.bulkScorer(context); if (scorer != null) { try { scorer.score(collector.getLeafCollector(context), context.reader().getLiveDocs()); } catch (CollectionTerminatedException e) { // collection was terminated prematurely // continue with the following leaf } } } }
@Override public void collect(int docID, CharSequence key, CharSequence context, float score) throws IOException { if (scoreDocMap.containsKey(docID)) { SuggestDoc suggestDoc = scoreDocMap.get(docID); suggestDoc.add(key, context, score); } else if (scoreDocMap.size() <= num) { scoreDocMap.put(docID, new SuggestDoc(docBase + docID, key, context, score)); } else { throw new CollectionTerminatedException(); } }
@Override public void doSetNextReader(LeafReaderContext context) throws IOException { if (docs.size() >= size || context.docBase + context.reader().maxDoc() <= docUpTo) { // no need to collect a new segment, we either already collected enough // or the segment is not competitive throw new CollectionTerminatedException(); } docBase = context.docBase; }
@Override public void collect(int doc) throws IOException { in.collect(doc); if (++numCollected >= segmentTotalCollect) { throw new CollectionTerminatedException(); } }
@Override public void collect( int doc ) throws IOException { result = doc; throw new CollectionTerminatedException(); }