public NearSpansUnordered(SpanNearQuery query, IndexReader reader) throws IOException { this.query = query; this.slop = query.getSlop(); SpanQuery[] clauses = query.getClauses(); queue = new CellQueue(clauses.length); for (int i = 0; i < clauses.length; i++) { SpansCell cell = new SpansCell(clauses[i].getPayloadSpans(reader), i); ordered.add(cell); } }
private void singleCellToPositionQueue() { maxEndPositionCell = subSpanCells.get(0); assert maxEndPositionCell.docID() == -1; assert maxEndPositionCell.startPosition() == -1; spanPositionQueue.add(maxEndPositionCell); }
/** * WARNING: The List is not necessarily in order of the the positions * @return * @throws IOException */ public Collection/*<byte[]>*/ getPayload() throws IOException { Set/*<byte[]*/ matchPayload = new HashSet(); for (SpansCell cell = first; cell != null; cell = cell.next) { if (cell.isPayloadAvailable()) { matchPayload.addAll(cell.getPayload()); } } return matchPayload; }
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()); }
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()); }
public int end() { return max.end(); }
public int doc() { return min().doc(); } public int start() { return min().start(); }
private boolean adjust(boolean condition) { if (length != -1) { totalLength -= length; // subtract old length } if (condition) { length = end() - start(); totalLength += length; // add new length if (max == null || doc() > max.doc() || (doc() == max.doc()) && (end() > max.end())) { max = this; } } more = condition; return condition; }
public boolean next() throws IOException { return adjust(spans.next()); }
/** * WARNING: The List is not necessarily in order of the the positions * @return * @throws IOException */ public Collection/*<byte[]>*/ getPayload() throws IOException { Set/*<byte[]*/ matchPayload = new HashSet(); for (SpansCell cell = first; cell != null; cell = cell.next) { if (cell.isPayloadAvailable()) { matchPayload.addAll(cell.getPayload()); } } return matchPayload; }
public int end() { return max.end(); }
public int doc() { return min().doc(); } public int start() { return min().start(); }
private boolean atMatch() { assert minPositionCell().docID() == maxEndPositionCell.docID(); return (maxEndPositionCell.endPosition() - minPositionCell().startPosition() - totalSpanLength) <= allowedSlop; }
@Override public int endPosition() { return atFirstInCurrentDoc ? -1 : oneExhaustedInCurrentDoc ? NO_MORE_POSITIONS : maxEndPositionCell.endPosition(); }
private boolean adjust(boolean condition) { if (length != -1) { totalLength -= length; // subtract old length } if (condition) { length = end() - start(); totalLength += length; // add new length if (max == null || doc() > max.doc() || (doc() == max.doc()) && (end() > max.end())) { max = this; } } more = condition; return condition; }
@Override public int nextStartPosition() throws IOException { int res = in.nextStartPosition(); if (res != NO_MORE_POSITIONS) { adjustLength(); } adjustMax(); // also after last end position in current doc. return res; }
private void adjustLength() { if (spanLength != -1) { totalSpanLength -= spanLength; // subtract old, possibly from a previous doc } assert in.startPosition() != NO_MORE_POSITIONS; spanLength = endPosition() - startPosition(); assert spanLength >= 0; totalSpanLength += spanLength; // add new }