alessandrobenedetti commented on code in PR #12253:
URL: https://github.com/apache/lucene/pull/12253#discussion_r1227821007


##########
lucene/queries/src/test/org/apache/lucene/queries/function/TestKnnVectorSimilarityFunctions.java:
##########
@@ -0,0 +1,263 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.queries.function;
+
+import java.util.List;
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.document.KnnByteVectorField;
+import org.apache.lucene.document.KnnFloatVectorField;
+import org.apache.lucene.document.SortedDocValuesField;
+import org.apache.lucene.document.StringField;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.index.VectorSimilarityFunction;
+import org.apache.lucene.queries.function.valuesource.ByteVectorFieldSource;
+import 
org.apache.lucene.queries.function.valuesource.ByteVectorSimilarityFunction;
+import 
org.apache.lucene.queries.function.valuesource.ConstByteVectorValueSource;
+import 
org.apache.lucene.queries.function.valuesource.ConstFloatVectorValueSource;
+import org.apache.lucene.queries.function.valuesource.FloatVectorFieldSource;
+import 
org.apache.lucene.queries.function.valuesource.FloatVectorSimilarityFunction;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.ScoreDoc;
+import org.apache.lucene.search.Sort;
+import org.apache.lucene.search.SortField;
+import org.apache.lucene.search.TopDocs;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.tests.analysis.MockAnalyzer;
+import org.apache.lucene.tests.index.RandomIndexWriter;
+import org.apache.lucene.tests.search.CheckHits;
+import org.apache.lucene.tests.util.LuceneTestCase;
+import org.apache.lucene.util.BytesRef;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class TestKnnVectorSimilarityFunctions extends LuceneTestCase {
+  static Directory dir;
+  static Analyzer analyzer;
+  static IndexReader reader;
+  static IndexSearcher searcher;
+  static final List<String> documents = List.of("1", "2");
+
+  @BeforeClass
+  public static void beforeClass() throws Exception {
+    dir = newDirectory();
+    analyzer = new MockAnalyzer(random());
+    IndexWriterConfig iwConfig = newIndexWriterConfig(analyzer);
+    iwConfig.setMergePolicy(newLogMergePolicy());
+    RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwConfig);
+
+    Document document = new Document();
+    document.add(new StringField("id", "1", Field.Store.NO));
+    document.add(new SortedDocValuesField("id", new BytesRef("1")));
+    document.add(new KnnFloatVectorField("knnFloatField1", new float[] {1.f, 
2.f, 3.f}));
+    document.add(new KnnFloatVectorField("knnFloatField2", new float[] {5.2f, 
3.2f, 3.1f}));
+
+    // add only to the first document
+    document.add(new KnnFloatVectorField("knnFloatField3", new float[] {1.0f, 
1.0f, 1.0f}));
+    document.add(new KnnByteVectorField("knnByteField3", new byte[] {1, 1, 
1}));
+
+    document.add(new KnnByteVectorField("knnByteField1", new byte[] {1, 2, 
3}));
+    document.add(new KnnByteVectorField("knnByteField2", new byte[] {4, 2, 
3}));
+    iw.addDocument(document);
+
+    Document document2 = new Document();
+    document2.add(new StringField("id", "2", Field.Store.NO));
+    document2.add(new SortedDocValuesField("id", new BytesRef("2")));
+    document2.add(new KnnFloatVectorField("knnFloatField1", new float[] {1.f, 
2.f, 3.f}));
+    document2.add(new KnnFloatVectorField("knnFloatField2", new float[] {5.2f, 
3.2f, 3.1f}));
+
+    document2.add(new KnnByteVectorField("knnByteField1", new byte[] {1, 2, 
3}));
+    document2.add(new KnnByteVectorField("knnByteField2", new byte[] {4, 2, 
3}));
+    iw.addDocument(document2);
+
+    reader = iw.getReader();
+    searcher = newSearcher(reader);
+    iw.close();
+  }
+
+  @AfterClass
+  public static void afterClass() throws Exception {
+    searcher = null;
+    reader.close();
+    reader = null;
+    dir.close();
+    dir = null;
+    analyzer.close();
+    analyzer = null;
+  }
+
+  @Test
+  public void 
floatVectorSimilarityBetweenConstVector_shouldReturnCorrectResult() throws 
Exception {

Review Comment:
   I think we have lost the changes in naming, from an old commit I see:
   vectorSimilarity_floatConstantVectors_shouldReturnFloatSimilarity
   
   vectorSimilarity_missingFloatVectorField_shouldReturnNaN
   
   vectorSimilarity_TwoVectorsWithDifferentDimensions_shouldRaiseException
   
   etc



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to