@Override public Spans getSpans(final LeafReaderContext context, Postings requiredPostings) throws IOException { Terms terms = context.reader().terms(field); if (terms == null) { return null; // field does not exist } ArrayList<Spans> subSpans = new ArrayList<>(clauses.size()); for (SpanWeight w : subWeights) { Spans subSpan = w.getSpans(context, requiredPostings); if (subSpan != null) { subSpans.add(subSpan); } else { return null; // all required } } // all NearSpans require at least two subSpans return (!inOrder) ? new NearSpansUnordered(slop, subSpans) : new NearSpansOrdered(slop, subSpans); }
@Override protected final boolean lessThan(Spans spans1, Spans spans2) { return positionsOrdered(spans1, spans2); }
public boolean next() throws IOException { if (firstTime) { initList(true); listToQueue(); // initialize queue firstTime = false; } else if (more) { if (min().next()) { // trigger further scanning if (min().doc() != max.doc()) { // maintain list queueToList(); queueStale = true; firstToLast(); // and move it to the end queueStale = true; listToQueue(); queueStale = false; if (atMatch()) { return true; more = min().next(); if (more) {
public boolean skipTo(int target) throws IOException { if (firstTime) { // initialize initList(false); for (SpansCell cell = first; more && cell!=null; cell=cell.next) { more = cell.skipTo(target); // skip all } if (more) { listToQueue(); } firstTime = false; } else { // normal case while (more && min().doc() < target) { // skip as needed if (min().skipTo(target)) { queue.adjustTop(); } else { more = false; } } } return more && (atMatch() || next()); }
@Override boolean twoPhaseCurrentDocMatches() throws IOException { // at doc with all subSpans subSpanCellsToPositionQueue(); while (true) { if (atMatch()) { atFirstInCurrentDoc = true; oneExhaustedInCurrentDoc = false; return true; } assert minPositionCell().startPosition() != NO_MORE_POSITIONS; if (minPositionCell().nextStartPosition() != NO_MORE_POSITIONS) { spanPositionQueue.updateTop(); } else { // exhausted a subSpan in current doc return false; } } }
@Override public int nextStartPosition() throws IOException { if (atFirstInCurrentDoc) { atFirstInCurrentDoc = false; return minPositionCell().startPosition(); } while (minPositionCell().startPosition() == -1) { // initially at current doc minPositionCell().nextStartPosition(); spanPositionQueue.updateTop(); } assert minPositionCell().startPosition() != NO_MORE_POSITIONS; while (true) { if (minPositionCell().nextStartPosition() == NO_MORE_POSITIONS) { oneExhaustedInCurrentDoc = true; return NO_MORE_POSITIONS; } spanPositionQueue.updateTop(); if (atMatch()) { return minPositionCell().startPosition(); } } }
private void initList(boolean next) throws IOException { for (int i = 0; more && i < ordered.size(); i++) { SpansCell cell = (SpansCell)ordered.get(i); if (next) more = cell.next(); // move to first entry if (more) { addToList(cell); // add to list } } }
public boolean next() throws IOException { if (firstTime) { initList(true); listToQueue(); // initialize queue firstTime = false; } else if (more) { if (min().next()) { // trigger further scanning if (min().doc() != max.doc()) { // maintain list queueToList(); queueStale = true; firstToLast(); // and move it to the end queueStale = true; listToQueue(); queueStale = false; if (atMatch()) { return true; more = min().next(); if (more) {
public boolean skipTo(int target) throws IOException { if (firstTime) { // initialize initList(false); for (SpansCell cell = first; more && cell!=null; cell=cell.next) { more = cell.skipTo(target); // skip all } if (more) { listToQueue(); } firstTime = false; } else { // normal case while (more && min().doc() < target) { // skip as needed if (min().skipTo(target)) { queue.adjustTop(); } else { more = false; } } } return more && (atMatch() || next()); }
@Override boolean twoPhaseCurrentDocMatches() throws IOException { // at doc with all subSpans subSpanCellsToPositionQueue(); while (true) { if (atMatch()) { atFirstInCurrentDoc = true; oneExhaustedInCurrentDoc = false; return true; } assert minPositionCell().startPosition() != NO_MORE_POSITIONS; if (minPositionCell().nextStartPosition() != NO_MORE_POSITIONS) { spanPositionQueue.updateTop(); } else { // exhausted a subSpan in current doc return false; } } }
@Override public int nextStartPosition() throws IOException { if (atFirstInCurrentDoc) { atFirstInCurrentDoc = false; return minPositionCell().startPosition(); } while (minPositionCell().startPosition() == -1) { // initially at current doc minPositionCell().nextStartPosition(); spanPositionQueue.updateTop(); } assert minPositionCell().startPosition() != NO_MORE_POSITIONS; while (true) { if (minPositionCell().nextStartPosition() == NO_MORE_POSITIONS) { oneExhaustedInCurrentDoc = true; return NO_MORE_POSITIONS; } spanPositionQueue.updateTop(); if (atMatch()) { return minPositionCell().startPosition(); } } }
private void initList(boolean next) throws IOException { for (int i = 0; more && i < ordered.size(); i++) { SpansCell cell = (SpansCell)ordered.get(i); if (next) more = cell.next(); // move to first entry if (more) { addToList(cell); // add to list } } }
public Spans getSpans(final IndexReader reader) throws IOException { if (clauses.size() == 0) // optimize 0-clause case return new SpanOrQuery(getClauses()).getPayloadSpans(reader); if (clauses.size() == 1) // optimize 1-clause case return ((SpanQuery)clauses.get(0)).getPayloadSpans(reader); return inOrder ? (PayloadSpans) new NearSpansOrdered(this, reader) : (PayloadSpans) new NearSpansUnordered(this, reader); }
@Override protected final boolean lessThan(SpansCell spans1, SpansCell spans2) { return positionsOrdered(spans1, spans2); } }
private void queueToList() throws IOException { last = first = null; while (queue.top() != null) { addToList((SpansCell)queue.pop()); } }
public Spans getSpans(final IndexReader reader) throws IOException { if (clauses.size() == 0) // optimize 0-clause case return new SpanOrQuery(getClauses()).getPayloadSpans(reader); if (clauses.size() == 1) // optimize 1-clause case return ((SpanQuery)clauses.get(0)).getPayloadSpans(reader); return inOrder ? (PayloadSpans) new NearSpansOrdered(this, reader) : (PayloadSpans) new NearSpansUnordered(this, reader); }
@Override protected final boolean lessThan(SpansCell spans1, SpansCell spans2) { return positionsOrdered(spans1, spans2); } }
private void queueToList() throws IOException { last = first = null; while (queue.top() != null) { addToList((SpansCell)queue.pop()); } }