mirror of https://github.com/apache/lucene.git
LUCENE-9401: include field in the complex pharse query's toString
This commit is contained in:
parent
63f0b6b706
commit
b9c7f50b6e
|
@ -278,6 +278,8 @@ Bug Fixes
|
|||
* LUCENE-9501: Fix a bug in IndexSortSortedNumericDocValuesRangeQuery where it could violate the
|
||||
DocIdSetIterator contract. (Julie Tibshirani)
|
||||
|
||||
* LUCENE-9401: Include field in ComplexPhraseQuery's toString() (Thomas Hecker via Munendra S N)
|
||||
|
||||
Documentation
|
||||
---------------------
|
||||
|
||||
|
|
|
@ -434,10 +434,15 @@ public class ComplexPhraseQueryParser extends QueryParser {
|
|||
|
||||
@Override
|
||||
public String toString(String field) {
|
||||
if (slopFactor == 0)
|
||||
return "\"" + phrasedQueryStringContents + "\"";
|
||||
else
|
||||
return "\"" + phrasedQueryStringContents + "\"" + "~" + slopFactor;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (!this.field.equals(field)) {
|
||||
sb.append(this.field).append(":");
|
||||
}
|
||||
sb.append("\"").append(phrasedQueryStringContents).append("\"");
|
||||
if (slopFactor != 0) {
|
||||
sb.append("~").append(slopFactor);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -169,12 +169,14 @@ public class TestComplexPhraseQuery extends LuceneTestCase {
|
|||
}
|
||||
|
||||
public void testToStringContainsSlop() throws Exception {
|
||||
ComplexPhraseQueryParser qp = new ComplexPhraseQueryParser(defaultFieldName, analyzer);
|
||||
ComplexPhraseQueryParser qp = new ComplexPhraseQueryParser("", analyzer);
|
||||
int slop = random().nextInt(31) + 1;
|
||||
|
||||
String qString = "name:\"j* smyth~\"~" + slop;
|
||||
Query query = qp.parse(qString);
|
||||
assertTrue("Slop is not shown in toString()", query.toString().endsWith("~" + slop));
|
||||
String actualQStr = query.toString();
|
||||
assertTrue("Slop is not shown in toString()", actualQStr.endsWith("~" + slop));
|
||||
assertEquals(qString, actualQStr);
|
||||
|
||||
String string = "\"j* smyth~\"";
|
||||
Query q = qp.parse(string);
|
||||
|
|
Loading…
Reference in New Issue