diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 4e530357faf..8432ad2286a 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -178,6 +178,8 @@ Other * GITHUB#13001: Put Thread#sleep() on the list of forbidden APIs. (Shubham Chaudhary) +* GITHUB#13077: Add public getter for SynonymQuery#field (Andrey Bozhko) + ======================== Lucene 9.11.0 ======================= API Changes diff --git a/lucene/core/src/java/org/apache/lucene/search/SynonymQuery.java b/lucene/core/src/java/org/apache/lucene/search/SynonymQuery.java index 807f41359c4..88bfc67ba40 100644 --- a/lucene/core/src/java/org/apache/lucene/search/SynonymQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/SynonymQuery.java @@ -115,10 +115,16 @@ public final class SynonymQuery extends Query { this.field = Objects.requireNonNull(field); } + /** Returns the terms of this {@link SynonymQuery} */ public List getTerms() { return Arrays.stream(terms).map(t -> new Term(field, t.term)).toList(); } + /** Returns the field name of this {@link SynonymQuery} */ + public String getField() { + return field; + } + @Override public String toString(String field) { StringBuilder builder = new StringBuilder("Synonym("); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestSynonymQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestSynonymQuery.java index f366debb9ce..b3a886d4964 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestSynonymQuery.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestSynonymQuery.java @@ -87,6 +87,12 @@ public class TestSynonymQuery extends LuceneTestCase { new SynonymQuery.Builder("field2").addTerm(new Term("field2", "b"), 0.4f).build()); } + public void testGetField() { + SynonymQuery query = + new SynonymQuery.Builder("field1").addTerm(new Term("field1", "a")).build(); + assertEquals("field1", query.getField()); + } + public void testBogusParams() { expectThrows( IllegalArgumentException.class,