Skip to content

Commit

Permalink
Add public getter for SynonymQuery#field
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyBozhko authored and mkhludnev committed Feb 27, 2024
1 parent 8a555eb commit c6c4141
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lucene/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,17 @@ private SynonymQuery(TermAndBoost[] terms, String field) {
this.field = Objects.requireNonNull(field);
}

/** Returns the terms of this {@link SynonymQuery} */
public List<Term> 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(");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit c6c4141

Please sign in to comment.