You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by eh...@apache.org on 2014/11/14 19:16:15 UTC
svn commit: r1639715 - in /lucene/dev/branches/branch_5x/lucene: ./ core/
core/src/java/org/apache/lucene/search/spans/
core/src/test/org/apache/lucene/search/spans/
Author: ehatcher
Date: Fri Nov 14 18:16:15 2014
New Revision: 1639715
URL: http://svn.apache.org/r1639715
Log:
LUCENE-3229: Overlapping ordered SpanNearQuery spans should not match.
Modified:
lucene/dev/branches/branch_5x/lucene/ (props changed)
lucene/dev/branches/branch_5x/lucene/CHANGES.txt (contents, props changed)
lucene/dev/branches/branch_5x/lucene/core/ (props changed)
lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/NearSpansOrdered.java
lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/NearSpansUnordered.java
lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanNearQuery.java
lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/TestNearSpansOrdered.java
Modified: lucene/dev/branches/branch_5x/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/CHANGES.txt?rev=1639715&r1=1639714&r2=1639715&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/branch_5x/lucene/CHANGES.txt Fri Nov 14 18:16:15 2014
@@ -329,6 +329,13 @@ Other
* LUCENE-5915: Remove Pulsing postings format. (Robert Muir)
+======================= Lucene 4.10.3 ======================
+
+Bug fixes
+
+* LUCENE-3229: Overlapping ordered SpanNearQuery spans should not match.
+ (Ludovic Boutros, Paul Elschot, Greg Dearing, ehatcher)
+
======================= Lucene 4.10.2 ======================
Bug fixes
Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/NearSpansOrdered.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/NearSpansOrdered.java?rev=1639715&r1=1639714&r2=1639715&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/NearSpansOrdered.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/NearSpansOrdered.java Fri Nov 14 18:16:15 2014
@@ -234,24 +234,23 @@ public class NearSpansOrdered extends Sp
return true;
}
- /** Check whether two Spans in the same document are ordered.
- * @return true iff spans1 starts before spans2
- * or the spans start at the same position,
- * and spans1 ends before spans2.
+ /** Check whether two Spans in the same document are ordered and not overlapping.
+ * @return false iff spans2's start position is smaller than spans1's end position
*/
- static final boolean docSpansOrdered(Spans spans1, Spans spans2) {
+ static final boolean docSpansOrderedNonOverlap(Spans spans1, Spans spans2) {
assert spans1.doc() == spans2.doc() : "doc1 " + spans1.doc() + " != doc2 " + spans2.doc();
- int start1 = spans1.start();
- int start2 = spans2.start();
- /* Do not call docSpansOrdered(int,int,int,int) to avoid invoking .end() : */
- return (start1 == start2) ? (spans1.end() < spans2.end()) : (start1 < start2);
+ assert spans1.start() < spans1.end();
+ assert spans2.start() < spans2.end();
+ return spans1.end() <= spans2.start();
}
- /** Like {@link #docSpansOrdered(Spans,Spans)}, but use the spans
+ /** Like {@link #docSpansOrderedNonOverlap(Spans,Spans)}, but use the spans
* starts and ends as parameters.
*/
- private static final boolean docSpansOrdered(int start1, int end1, int start2, int end2) {
- return (start1 == start2) ? (end1 < end2) : (start1 < start2);
+ private static final boolean docSpansOrderedNonOverlap(int start1, int end1, int start2, int end2) {
+ assert start1 < end1;
+ assert start2 < end2;
+ return end1 <= start2;
}
/** Order the subSpans within the same document by advancing all later spans
@@ -260,7 +259,7 @@ public class NearSpansOrdered extends Sp
private boolean stretchToOrder() throws IOException {
matchDoc = subSpans[0].doc();
for (int i = 1; inSameDoc && (i < subSpans.length); i++) {
- while (! docSpansOrdered(subSpans[i-1], subSpans[i])) {
+ while (! docSpansOrderedNonOverlap(subSpans[i-1], subSpans[i])) {
if (! subSpans[i].next()) {
inSameDoc = false;
more = false;
@@ -312,7 +311,7 @@ public class NearSpansOrdered extends Sp
} else {
int ppStart = prevSpans.start();
int ppEnd = prevSpans.end(); // Cannot avoid invoking .end()
- if (! docSpansOrdered(ppStart, ppEnd, lastStart, lastEnd)) {
+ if (! docSpansOrderedNonOverlap(ppStart, ppEnd, lastStart, lastEnd)) {
break; // Check remaining subSpans.
} else { // prevSpans still before (lastStart, lastEnd)
prevStart = ppStart;
Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/NearSpansUnordered.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/NearSpansUnordered.java?rev=1639715&r1=1639714&r2=1639715&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/NearSpansUnordered.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/NearSpansUnordered.java Fri Nov 14 18:16:15 2014
@@ -63,7 +63,7 @@ public class NearSpansUnordered extends
@Override
protected final boolean lessThan(SpansCell spans1, SpansCell spans2) {
if (spans1.doc() == spans2.doc()) {
- return NearSpansOrdered.docSpansOrdered(spans1, spans2);
+ return docSpansOrdered(spans1, spans2);
} else {
return spans1.doc() < spans2.doc();
}
@@ -233,6 +233,18 @@ public class NearSpansUnordered extends
return more && (atMatch() || next());
}
+ /** 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 final boolean docSpansOrdered(Spans spans1, Spans spans2) {
+ assert spans1.doc() == spans2.doc() : "doc1 " + spans1.doc() + " != doc2 " + spans2.doc();
+ int start1 = spans1.start();
+ int start2 = spans2.start();
+ return (start1 == start2) ? (spans1.end() < spans2.end()) : (start1 < start2);
+ }
+
private SpansCell min() { return queue.top(); }
@Override
Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanNearQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanNearQuery.java?rev=1639715&r1=1639714&r2=1639715&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanNearQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanNearQuery.java Fri Nov 14 18:16:15 2014
@@ -48,12 +48,15 @@ public class SpanNearQuery extends SpanQ
/** Construct a SpanNearQuery. Matches spans matching a span from each
* clause, with up to <code>slop</code> total unmatched positions between
- * them. * When <code>inOrder</code> is true, the spans from each clause
- * must be * ordered as in <code>clauses</code>.
+ * them.
+ * <br>When <code>inOrder</code> is true, the spans from each clause
+ * must be in the same order as in <code>clauses</code> and must be non-overlapping.
+ * <br>When <code>inOrder</code> is false, the spans from each clause
+ * need not be ordered and may overlap.
* @param clauses the clauses to find near each other
* @param slop The slop value
* @param inOrder true if order is important
- * */
+ */
public SpanNearQuery(SpanQuery[] clauses, int slop, boolean inOrder) {
this(clauses, slop, inOrder, true);
}
Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/TestNearSpansOrdered.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/TestNearSpansOrdered.java?rev=1639715&r1=1639714&r2=1639715&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/TestNearSpansOrdered.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/TestNearSpansOrdered.java Fri Nov 14 18:16:15 2014
@@ -82,6 +82,22 @@ public class TestNearSpansOrdered extend
protected SpanNearQuery makeQuery() {
return makeQuery("w1","w2","w3",1,true);
}
+
+ protected SpanNearQuery makeOverlappedQuery(
+ String sqt1, String sqt2, boolean sqOrdered,
+ String t3, boolean ordered) {
+ return new SpanNearQuery(
+ new SpanQuery[] {
+ new SpanNearQuery(new SpanQuery[] {
+ new SpanTermQuery(new Term(FIELD, sqt1)),
+ new SpanTermQuery(new Term(FIELD, sqt2)) },
+ 1,
+ sqOrdered
+ ),
+ new SpanTermQuery(new Term(FIELD, t3)) },
+ 0,
+ ordered);
+ }
public void testSpanNearQuery() throws Exception {
SpanNearQuery q = makeQuery();
@@ -170,6 +186,22 @@ public class TestNearSpansOrdered extend
Scorer s = w.scorer(leave, leave.reader().getLiveDocs());
assertEquals(1, s.advance(1));
}
+
+ public void testOverlappedOrderedSpan() throws Exception {
+ SpanNearQuery q = makeOverlappedQuery("w5", "w3", false, "w4", true);
+ CheckHits.checkHits(random(), q, FIELD, searcher, new int[] {});
+ }
+
+ public void testOverlappedNonOrderedSpan() throws Exception {
+ SpanNearQuery q = makeOverlappedQuery("w3", "w5", true, "w4", false);
+ CheckHits.checkHits(random(), q, FIELD, searcher, new int[] {0});
+ }
+
+ public void testNonOverlappedOrderedSpan() throws Exception {
+ SpanNearQuery q = makeOverlappedQuery("w3", "w4", true, "w5", true);
+ CheckHits.checkHits(random(), q, FIELD, searcher, new int[] {0});
+ }
+
/**
* not a direct test of NearSpans, but a demonstration of how/when
@@ -182,5 +214,4 @@ public class TestNearSpansOrdered extend
+ e.toString(),
0.0f < e.getValue());
}
-
}