From a8baa47733130b88e35d4b7ebddcf23ee1b22b1a Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Wed, 14 Jun 2023 11:54:10 +0200 Subject: [PATCH] Move TermAndBoost back to its original location. (#12366) PR #12169 accidentally moved the `TermAndBoost` class to a different location, which would break custom sub-classes of `QueryBuilder`. This commit moves it back to its original location. --- .../analysis/synonym/word2vec}/TermAndBoost.java | 4 +++- .../synonym/word2vec/Word2VecSynonymFilter.java | 1 - .../synonym/word2vec/Word2VecSynonymProvider.java | 1 - .../word2vec/TestWord2VecSynonymProvider.java | 1 - .../java/org/apache/lucene/util/QueryBuilder.java | 14 ++++++++++++++ 5 files changed, 17 insertions(+), 4 deletions(-) rename lucene/{core/src/java/org/apache/lucene/util => analysis/common/src/java/org/apache/lucene/analysis/synonym/word2vec}/TermAndBoost.java (92%) diff --git a/lucene/core/src/java/org/apache/lucene/util/TermAndBoost.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/synonym/word2vec/TermAndBoost.java similarity index 92% rename from lucene/core/src/java/org/apache/lucene/util/TermAndBoost.java rename to lucene/analysis/common/src/java/org/apache/lucene/analysis/synonym/word2vec/TermAndBoost.java index 0c7958a99a0..03fdeecb0f2 100644 --- a/lucene/core/src/java/org/apache/lucene/util/TermAndBoost.java +++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/synonym/word2vec/TermAndBoost.java @@ -14,7 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.lucene.util; +package org.apache.lucene.analysis.synonym.word2vec; + +import org.apache.lucene.util.BytesRef; /** Wraps a term and boost */ public class TermAndBoost { diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/synonym/word2vec/Word2VecSynonymFilter.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/synonym/word2vec/Word2VecSynonymFilter.java index 6088d8d6efc..a8db4c4c764 100644 --- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/synonym/word2vec/Word2VecSynonymFilter.java +++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/synonym/word2vec/Word2VecSynonymFilter.java @@ -29,7 +29,6 @@ import org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute; import org.apache.lucene.analysis.tokenattributes.TypeAttribute; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRefBuilder; -import org.apache.lucene.util.TermAndBoost; /** * Applies single-token synonyms from a Word2Vec trained network to an incoming {@link TokenStream}. diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/synonym/word2vec/Word2VecSynonymProvider.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/synonym/word2vec/Word2VecSynonymProvider.java index 4660879922e..3089f1587a4 100644 --- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/synonym/word2vec/Word2VecSynonymProvider.java +++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/synonym/word2vec/Word2VecSynonymProvider.java @@ -26,7 +26,6 @@ import java.util.List; import org.apache.lucene.index.VectorEncoding; import org.apache.lucene.index.VectorSimilarityFunction; import org.apache.lucene.util.BytesRef; -import org.apache.lucene.util.TermAndBoost; import org.apache.lucene.util.hnsw.HnswGraphBuilder; import org.apache.lucene.util.hnsw.HnswGraphSearcher; import org.apache.lucene.util.hnsw.NeighborQueue; diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/synonym/word2vec/TestWord2VecSynonymProvider.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/synonym/word2vec/TestWord2VecSynonymProvider.java index 0803406bdaf..3e7e6bce07a 100644 --- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/synonym/word2vec/TestWord2VecSynonymProvider.java +++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/synonym/word2vec/TestWord2VecSynonymProvider.java @@ -21,7 +21,6 @@ import java.io.IOException; import java.util.List; import org.apache.lucene.tests.util.LuceneTestCase; import org.apache.lucene.util.BytesRef; -import org.apache.lucene.util.TermAndBoost; import org.apache.lucene.util.TermAndVector; import org.junit.Test; diff --git a/lucene/core/src/java/org/apache/lucene/util/QueryBuilder.java b/lucene/core/src/java/org/apache/lucene/util/QueryBuilder.java index adf30baec29..3ad17dca5ce 100644 --- a/lucene/core/src/java/org/apache/lucene/util/QueryBuilder.java +++ b/lucene/core/src/java/org/apache/lucene/util/QueryBuilder.java @@ -62,6 +62,20 @@ public class QueryBuilder { protected boolean enableGraphQueries = true; protected boolean autoGenerateMultiTermSynonymsPhraseQuery = false; + /** Wraps a term and boost */ + public static class TermAndBoost { + /** the term */ + public final BytesRef term; + /** the boost */ + public final float boost; + + /** Creates a new TermAndBoost */ + public TermAndBoost(BytesRef term, float boost) { + this.term = BytesRef.deepCopyOf(term); + this.boost = boost; + } + } + /** Creates a new QueryBuilder using the given analyzer. */ public QueryBuilder(Analyzer analyzer) { this.analyzer = analyzer;