Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-4970: Fix boost value of rewritten NGramPhraseQuery.

Adrien Grand2e7f226afe4a
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 2c4adfffcad..db26cce8920 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -73,6 +73,9 @@ Bug Fixes
the child query has no hits, more aggressively catch cases where childQuery
incorrectly matches parent documents (Mike McCandless)
+* LUCENE-4970: Fix boost value of rewritten NGramPhraseQuery.
+ (Shingo Sasaki via Adrien Grand)
+
Optimizations
* LUCENE-4938: Don't use an unnecessarily large priority queue in IndexSearcher
diff --git a/lucene/core/src/java/org/apache/lucene/search/NGramPhraseQuery.java b/lucene/core/src/java/org/apache/lucene/search/NGramPhraseQuery.java
index 54d396e852a..734498aec7e 100644
--- a/lucene/core/src/java/org/apache/lucene/search/NGramPhraseQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/NGramPhraseQuery.java
@@ -64,6 +64,7 @@ public class NGramPhraseQuery extends PhraseQuery {
// now create the new optimized phrase query for n-gram
PhraseQuery optimized = new PhraseQuery();
+ optimized.setBoost(getBoost());
int pos = 0;
final int lastPos = terms.length - 1;
for(int i = 0; i < terms.length; i++){
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestNGramPhraseQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestNGramPhraseQuery.java
index 8eb50814086..648b2a879cb 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestNGramPhraseQuery.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestNGramPhraseQuery.java
@@ -88,6 +88,17 @@ public class TestNGramPhraseQuery extends LuceneTestCase {
pq3 = (PhraseQuery)q;
assertArrayEquals(new Term[]{new Term("f", "ABC"), new Term("f", "DEF"), new Term("f", "FGH")}, pq3.getTerms());
assertArrayEquals(new int[]{0, 3, 5}, pq3.getPositions());
+
+ // LUCENE-4970: boosting test
+ PhraseQuery pq4 = new NGramPhraseQuery(2);
+ pq4.add(new Term("f", "AB"));
+ pq4.add(new Term("f", "BC"));
+ pq4.add(new Term("f", "CD"));
+ pq4.setBoost(100.0F);
+
+ q = pq4.rewrite(reader);
+ assertNotSame(pq4, q);
+ assertEquals(pq4.getBoost(), q.getBoost(), 0.1f);
}
}