Add getter for SynonymQuery#field (#13077)

---------

Co-authored-by: Andrey Bozhko <abozhko@apple.com>
This commit is contained in:
Andrey Bozhko 2024-02-27 02:43:45 -06:00 committed by GitHub
parent bf6f38665e
commit 6764a01805
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 0 deletions

View File

@ -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

View File

@ -115,10 +115,16 @@ public final class SynonymQuery extends Query {
this.field = Objects.requireNonNull(field);
}
/** Returns the terms of this {@link SynonymQuery} */
public List<Term> 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(");

View File

@ -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,