LUCENE-8094: improve TermInSetQuery.toString

This commit is contained in:
Mike McCandless 2017-12-21 13:57:24 -05:00
parent f354a278f8
commit 1b201d04d7
3 changed files with 10 additions and 4 deletions

View File

@ -97,6 +97,8 @@ Improvements
* LUCENE-8093: TrimFilterFactory implements MultiTermAwareComponent (Alan Woodward) * LUCENE-8093: TrimFilterFactory implements MultiTermAwareComponent (Alan Woodward)
* LUCENE-8094: TermInSetQuery.toString now returns "field:(A B C)" (Mike McCandless)
Bug Fixes Bug Fixes
* LUCENE-8077: Fixed bug in how CheckIndex verifies doc-value iterators. * LUCENE-8077: Fixed bug in how CheckIndex verifies doc-value iterators.

View File

@ -148,15 +148,19 @@ public class TermInSetQuery extends Query implements Accountable {
@Override @Override
public String toString(String defaultField) { public String toString(String defaultField) {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
boolean first = true; builder.append(field);
builder.append(":(");
TermIterator iterator = termData.iterator(); TermIterator iterator = termData.iterator();
boolean first = true;
for (BytesRef term = iterator.next(); term != null; term = iterator.next()) { for (BytesRef term = iterator.next(); term != null; term = iterator.next()) {
if (!first) { if (!first) {
builder.append(' '); builder.append(' ');
} }
first = false; first = false;
builder.append(new Term(iterator.field(), term).toString()); builder.append(Term.toString(term));
} }
builder.append(')');
return builder.toString(); return builder.toString();
} }

View File

@ -157,7 +157,7 @@ public class TermInSetQueryTest extends LuceneTestCase {
public void testToString() { public void testToString() {
TermInSetQuery termsQuery = new TermInSetQuery("field1", TermInSetQuery termsQuery = new TermInSetQuery("field1",
new BytesRef("a"), new BytesRef("b"), new BytesRef("c")); new BytesRef("a"), new BytesRef("b"), new BytesRef("c"));
assertEquals("field1:a field1:b field1:c", termsQuery.toString()); assertEquals("field1:(a b c)", termsQuery.toString());
} }
public void testDedup() { public void testDedup() {
@ -285,7 +285,7 @@ public class TermInSetQueryTest extends LuceneTestCase {
public void testBinaryToString() { public void testBinaryToString() {
TermInSetQuery query = new TermInSetQuery("field", new BytesRef(new byte[] { (byte) 0xff, (byte) 0xfe })); TermInSetQuery query = new TermInSetQuery("field", new BytesRef(new byte[] { (byte) 0xff, (byte) 0xfe }));
assertEquals("field:[ff fe]", query.toString()); assertEquals("field:([ff fe])", query.toString());
} }
public void testIsConsideredCostlyByQueryCache() throws IOException { public void testIsConsideredCostlyByQueryCache() throws IOException {