@Override public SpanWeight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException { SpanWeight bigWeight = big.createWeight(searcher, false, boost); SpanWeight littleWeight = little.createWeight(searcher, false, boost); return new SpanContainingWeight(searcher, needsScores ? getTermContexts(bigWeight, littleWeight) : null, bigWeight, littleWeight, boost); }
@Override public SpanWeight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException { SpanWeight includeWeight = include.createWeight(searcher, false, boost); SpanWeight excludeWeight = exclude.createWeight(searcher, false, boost); return new SpanNotWeight(searcher, needsScores ? getTermContexts(includeWeight, excludeWeight) : null, includeWeight, excludeWeight, boost); }
@Override public SpanScorer scorer(LeafReaderContext context) throws IOException { final Spans spans = getSpans(context, Postings.POSITIONS); if (spans == null) { return null; } final Similarity.SimScorer docScorer = getSimScorer(context); return new SpanScorer(this, spans, docScorer); }
@Override public int nextStartPosition() throws IOException { if (topPositionSpans == null) { byPositionQueue.clear(); fillPositionQueue(); // fills byPositionQueue at first position topPositionSpans = byPositionQueue.top(); } else { topPositionSpans.nextStartPosition(); topPositionSpans = byPositionQueue.updateTop(); } return topPositionSpans.startPosition(); }
/** Check whether two Spans in the same document are ordered with possible overlap. * @return true iff spans1 starts before spans2 * or the spans start at the same position, * and spans1 ends before spans2. */ static boolean positionsOrdered(Spans spans1, Spans spans2) { assert spans1.docID() == spans2.docID() : "doc1 " + spans1.docID() + " != doc2 " + spans2.docID(); int start1 = spans1.startPosition(); int start2 = spans2.startPosition(); return (start1 == start2) ? (spans1.endPosition() < spans2.endPosition()) : (start1 < start2); }
private static int advancePosition(Spans spans, int position) throws IOException { if (spans instanceof SpanNearQuery.GapSpans) { return ((SpanNearQuery.GapSpans)spans).skipToPosition(position); } while (spans.startPosition() < position) { spans.nextStartPosition(); } return spans.startPosition(); }
@Override public Query rewrite(IndexReader reader) throws IOException { SpanQuery rewrittenInclude = (SpanQuery) include.rewrite(reader); SpanQuery rewrittenExclude = (SpanQuery) exclude.rewrite(reader); if (rewrittenInclude != include || rewrittenExclude != exclude) { return new SpanNotQuery(rewrittenInclude, rewrittenExclude, pre, post); } return super.rewrite(reader); } /** Returns true iff <code>o</code> is equal to this. */
@Override boolean twoPhaseCurrentDocMatches() throws IOException { assert unpositioned(); oneExhaustedInCurrentDoc = false; while (subSpans[0].nextStartPosition() != NO_MORE_POSITIONS && !oneExhaustedInCurrentDoc) { if (stretchToOrder() && matchWidth <= allowedSlop) { return atFirstInCurrentDoc = true; } } return false; }
@Override public final int advance(int target) throws IOException { int doc = in.advance(target); while (doc != NO_MORE_DOCS) { if (twoPhaseCurrentDocMatches()) { break; } doc = in.nextDoc(); } return doc; }
@Override public Query rewrite(IndexReader reader) throws IOException { SpanQuery rewritten = (SpanQuery) maskedQuery.rewrite(reader); if (rewritten != maskedQuery) { return new FieldMaskingSpanQuery(rewritten, field); } return super.rewrite(reader); }
@Override public SpanWeight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException { SpanWeight matchWeight = match.createWeight(searcher, false, boost); return new SpanPositionCheckWeight(matchWeight, searcher, needsScores ? getTermContexts(matchWeight) : null, boost); }
@Override public SpanWeight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException { SpanWeight bigWeight = big.createWeight(searcher, false, boost); SpanWeight littleWeight = little.createWeight(searcher, false, boost); return new SpanWithinWeight(searcher, needsScores ? getTermContexts(bigWeight, littleWeight) : null, bigWeight, littleWeight, boost); }
boolean atMatch() { boolean res = (maxEndPosition - top().startPosition() - totalSpanLength) <= allowedSlop; return res; } }
@Override public final int nextDoc() throws IOException { while (true) { int doc = in.nextDoc(); if (doc == NO_MORE_DOCS) { return NO_MORE_DOCS; } else if (twoPhaseCurrentDocMatches()) { return doc; } } }
@Override public int startPosition() { return atFirstInCurrentDoc ? -1 : oneExhaustedInCurrentDoc ? NO_MORE_POSITIONS : sourceSpans.startPosition(); }
/** Returns true iff <code>other</code> is equal to this. */ @Override public boolean equals(Object other) { return sameClassAs(other) && match.equals(((SpanPositionCheckQuery) other).match); }
@Override public void extractTermContexts(Map<Term, TermContext> contexts) { for (SpanWeight w : subWeights) { w.extractTermContexts(contexts); } }
@Override public int width() { return spanWindow.maxEndPosition - spanWindow.top().startPosition(); }
@Override public int startPosition() { assert spanWindow.top() != null; return atFirstInCurrentDoc ? -1 : oneExhaustedInCurrentDoc ? NO_MORE_POSITIONS : spanWindow.top().startPosition(); }