Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-7284: GapSpans needs to implement positionsCost()

Alan Woodwardcfc13f5b67e9
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 73a4c21f320..1302684058b 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -118,6 +118,9 @@ Bug Fixes
* LUCENE-7279: JapaneseTokenizer throws ArrayIndexOutOfBoundsException
on some valid inputs (Mike McCandless)
+* LUCENE-7284: GapSpans needs to implement positionsCost(). (Daniel Bigham, Alan
+ Woodward)
+
Documentation
* LUCENE-7223: Improve XXXPoint javadocs to make it clear that you
diff --git a/lucene/core/src/java/org/apache/lucene/search/spans/SpanNearQuery.java b/lucene/core/src/java/org/apache/lucene/search/spans/SpanNearQuery.java
index 167a7d1fb0e..d542227b37f 100644
--- a/lucene/core/src/java/org/apache/lucene/search/spans/SpanNearQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/spans/SpanNearQuery.java
@@ -386,7 +386,7 @@ public class SpanNearQuery extends SpanQuery implements Cloneable {
@Override
public float positionsCost() {
- throw new UnsupportedOperationException();
+ return 0;
}
}
diff --git a/lucene/core/src/test/org/apache/lucene/search/spans/TestNearSpansOrdered.java b/lucene/core/src/test/org/apache/lucene/search/spans/TestNearSpansOrdered.java
index f297f33676d..d9c003a9002 100644
--- a/lucene/core/src/test/org/apache/lucene/search/spans/TestNearSpansOrdered.java
+++ b/lucene/core/src/test/org/apache/lucene/search/spans/TestNearSpansOrdered.java
@@ -29,6 +29,7 @@ import org.apache.lucene.search.CheckHits;
import org.apache.lucene.search.Explanation;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Scorer;
+import org.apache.lucene.search.TopDocs;
import org.apache.lucene.search.Weight;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.LuceneTestCase;
@@ -72,7 +73,8 @@ public class TestNearSpansOrdered extends LuceneTestCase {
"w1 xx w2 yy w3",
"w1 w3 xx w2 yy w3 zz",
"t1 t2 t2 t1",
- "g x x g g x x x g g x x g"
+ "g x x g g x x x g g x x g",
+ "go to webpage"
};
protected SpanNearQuery makeQuery(String s1, String s2, String s3,
@@ -292,6 +294,23 @@ public class TestNearSpansOrdered extends LuceneTestCase {
assertFinished(spans);
}
+ public void testNestedGaps() throws Exception {
+ SpanQuery q = SpanNearQuery.newOrderedNearQuery(FIELD)
+ .addClause(new SpanOrQuery(
+ new SpanTermQuery(new Term(FIELD, "open")),
+ SpanNearQuery.newOrderedNearQuery(FIELD)
+ .addClause(new SpanTermQuery(new Term(FIELD, "go")))
+ .addGap(1)
+ .build()
+ ))
+ .addClause(new SpanTermQuery(new Term(FIELD, "webpage")))
+ .build();
+
+ TopDocs topDocs = searcher.search(q, 1);
+ assertEquals(6, topDocs.scoreDocs[0].doc);
+
+ }
+
/*
protected String[] docFields = {
"w1 w2 w3 w4 w5",
@@ -299,7 +318,8 @@ public class TestNearSpansOrdered extends LuceneTestCase {
"w1 xx w2 yy w3",
"w1 w3 xx w2 yy w3 zz",
"t1 t2 t2 t1",
- "g x x g g x x x g g x x g"
+ "g x x g g x x x g g x x g",
+ "go to webpage"
};
*/
}