cutting 2004/05/11 12:36:23 Modified: src/java/org/apache/lucene/search/spans NearSpans.java Log: Fix for bug 28285, from Paul Elschot. Revision Changes Path 1.5 +51 -15 jakarta-lucene/src/java/org/apache/lucene/search/spans/NearSpans.java Index: NearSpans.java =================================================================== RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/search/spans/NearSpans.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- NearSpans.java 9 Feb 2004 22:25:51 -0000 1.4 +++ NearSpans.java 11 May 2004 19:36:23 -0000 1.5 @@ -177,10 +177,20 @@ if (atMatch()) return true; - - more = min().next(); // trigger further scanning - if (more) - queue.adjustTop(); // maintain queue + + // trigger further scanning + if (inOrder && checkSlop()) { + /* There is a non ordered match within slop and an ordered match is needed. */ + more = firstNonOrderedNextToPartialList(); + if (more) { + partialListToQueue(); + } + } else { + more = min().next(); + if (more) { + queue.adjustTop(); // maintain queue + } + } } return false; // no more matches } @@ -258,23 +268,50 @@ addToList((SpansCell)queue.pop()); } } + + private boolean firstNonOrderedNextToPartialList() throws IOException { + /* Creates a partial list consisting of first non ordered and earlier. + * Returns first non ordered .next(). + */ + last = first = null; + int orderedIndex = 0; + while (queue.top() != null) { + SpansCell cell = (SpansCell)queue.pop(); + addToList(cell); + if (cell.index == orderedIndex) { + orderedIndex++; + } else { + return cell.next(); + // FIXME: continue here, rename to eg. checkOrderedMatch(): + // when checkSlop() and not ordered, repeat cell.next(). + // when checkSlop() and ordered, add to list and repeat queue.pop() + // without checkSlop(): no match, rebuild the queue from the partial list. + // When queue is empty and checkSlop() and ordered there is a match. + } + } + throw new AssertionError("Unexpected: ordered"); + } private void listToQueue() { - queue.clear(); + queue.clear(); // rebuild queue + partialListToQueue(); + } + + private void partialListToQueue() { for (SpansCell cell = first; cell != null; cell = cell.next) { - queue.put(cell); // build queue from list + queue.put(cell); // add to queue from list } } private boolean atMatch() { - if (min().doc() == max.doc()) { // at a match? - int matchLength = max.end() - min().start(); - if (((matchLength - totalLength) <= slop) // check slop - && (!inOrder || matchIsOrdered())) { // check order - return true; - } - } - return false; + return (min().doc() == max.doc()) + && checkSlop() + && (!inOrder || matchIsOrdered()); + } + + private boolean checkSlop() { + int matchLength = max.end() - min().start(); + return (matchLength - totalLength) <= slop; } private boolean matchIsOrdered() { @@ -287,5 +324,4 @@ } return true; } - }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]