From 09496a61a5402eae1abc046cff3f8dec1050b9fa Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Fri, 11 Sep 2015 14:46:18 +0000 Subject: [PATCH] LUCENE-6792: Fix TermsQuery.toString to work with binary terms git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1702484 13f79535-47bb-0310-9956-ffa450edef68 --- lucene/CHANGES.txt | 3 +++ .../src/java/org/apache/lucene/queries/TermsQuery.java | 3 +-- .../src/test/org/apache/lucene/queries/TermsQueryTest.java | 5 +++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 4dec711f44f..9beb049c4f8 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -123,6 +123,9 @@ Bug Fixes * LUCENE-6776: Fix geo3d math to handle randomly squashed planet models (Karl Wright via Mike McCandless) +* LUCENE-6792: Fix TermsQuery.toString() to work with binary terms. + (Ruslan Muzhikov, Robert Muir) + Other * LUCENE-6174: Improve "ant eclipse" to select right JRE for building. diff --git a/lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java b/lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java index 19484cebc57..79e1470b789 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java @@ -182,8 +182,7 @@ public class TermsQuery extends Query implements Accountable { builder.append(' '); } first = false; - builder.append(iterator.field()).append(':'); - builder.append(term.utf8ToString()); + builder.append(new Term(iterator.field(), term).toString()); } return builder.toString(); diff --git a/lucene/queries/src/test/org/apache/lucene/queries/TermsQueryTest.java b/lucene/queries/src/test/org/apache/lucene/queries/TermsQueryTest.java index bddd78ef3a5..831ccf3ad0b 100644 --- a/lucene/queries/src/test/org/apache/lucene/queries/TermsQueryTest.java +++ b/lucene/queries/src/test/org/apache/lucene/queries/TermsQueryTest.java @@ -321,4 +321,9 @@ public class TermsQueryTest extends LuceneTestCase { wrapped.close(); dir.close(); } + + public void testBinaryToString() { + TermsQuery query = new TermsQuery(new Term("field", new BytesRef(new byte[] { (byte) 0xff, (byte) 0xfe }))); + assertEquals("field:[ff fe]", query.toString()); + } }