diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 78c4912f75fa..2cff3a2625d8 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -38,6 +38,8 @@ Other * GITHUB#13068: Replace numerous `brToString(BytesRef)` copies with a `ToStringUtils` method (Dmitry Cherniachenko) +* GITHUB#13077: Add public getter for SynonymQuery#field (Andrey Bozhko) + ======================== Lucene 9.10.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 f44ceaf3ac89..fb64a4eafdf0 100644 --- a/lucene/core/src/java/org/apache/lucene/search/SynonymQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/SynonymQuery.java @@ -116,11 +116,17 @@ private SynonymQuery(TermAndBoost[] terms, String field) { this.field = Objects.requireNonNull(field); } + /** Returns the terms of this {@link SynonymQuery} */ public List getTerms() { return Collections.unmodifiableList( Arrays.stream(terms).map(t -> new Term(field, t.term)).collect(Collectors.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 f366debb9ce5..b3a886d49647 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 void testEquals() { 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,