LUCENE-6817: ComplexPhraseQueryParser.ComplexPhraseQuery does not display slop in toString().

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1707043 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dawid Weiss 2015-10-06 12:49:07 +00:00
parent 393065d27b
commit fce60c94bb
3 changed files with 20 additions and 1 deletions

View File

@ -127,6 +127,9 @@ Optimizations
Bug Fixes
* LUCENE-6817: ComplexPhraseQueryParser.ComplexPhraseQuery does not display
slop in toString(). (Ahmet Arslan via Dawid Weiss)
* LUCENE-6730: Hyper-parameter c is ignored in term frequency NormalizationH1.
(Ahmet Arslan via Robert Muir)

View File

@ -399,7 +399,10 @@ public class ComplexPhraseQueryParser extends QueryParser {
@Override
public String toString(String field) {
return "\"" + phrasedQueryStringContents + "\"";
if (slopFactor == 0)
return "\"" + phrasedQueryStringContents + "\"";
else
return "\"" + phrasedQueryStringContents + "\"" + "~" + slopFactor;
}
@Override

View File

@ -139,6 +139,19 @@ public class TestComplexPhraseQuery extends LuceneTestCase {
checkMatches("name:\"john smith\"~2 AND role:designer AND id:3", "3");
}
public void testToStringContainsSlop() throws Exception {
ComplexPhraseQueryParser qp = new ComplexPhraseQueryParser(defaultFieldName, 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 string = "\"j* smyth~\"";
Query q = qp.parse(string);
assertEquals("Don't show implicit slop of zero", q.toString(), string);
}
public void testHashcodeEquals() throws Exception {
ComplexPhraseQueryParser qp = new ComplexPhraseQueryParser(defaultFieldName, analyzer);
qp.setInOrder(true);