You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mk...@apache.org on 2024/02/27 08:43:50 UTC
(lucene) branch main updated: Add getter for SynonymQuery#field (#13077)
This is an automated email from the ASF dual-hosted git repository.
mkhl pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/lucene.git
The following commit(s) were added to refs/heads/main by this push:
new 6764a018051 Add getter for SynonymQuery#field (#13077)
6764a018051 is described below
commit 6764a01805132d69bbca8eec2e28c070588fe52d
Author: Andrey Bozhko <an...@gmail.com>
AuthorDate: Tue Feb 27 02:43:45 2024 -0600
Add getter for SynonymQuery#field (#13077)
---------
Co-authored-by: Andrey Bozhko <ab...@apple.com>
---
lucene/CHANGES.txt | 2 ++
lucene/core/src/java/org/apache/lucene/search/SynonymQuery.java | 6 ++++++
lucene/core/src/test/org/apache/lucene/search/TestSynonymQuery.java | 6 ++++++
3 files changed, 14 insertions(+)
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<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(");
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,