rmuir commented on code in PR #13749:
URL: https://github.com/apache/lucene/pull/13749#discussion_r1752981586


##########
lucene/core/src/java/org/apache/lucene/search/similarities/TFSimilarity.java:
##########
@@ -0,0 +1,41 @@
+/*
+ * 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.search.similarities;
+
+import org.apache.lucene.index.FieldInvertState;
+import org.apache.lucene.search.CollectionStatistics;
+import org.apache.lucene.search.TermStatistics;
+
+/** Similarity that returns the TF as score */
+public class TFSimilarity extends Similarity {
+
+  @Override
+  public long computeNorm(FieldInvertState state) {
+    return 1; // we dont care
+  }

Review Comment:
   I'd also support removing this footgun as a separate PR. Similarity is 
supposed to be an "expert" interface, but this abstract method that impacts the 
index format is trappy, for the reasons shown here.
   
   Maybe it should have a default implementation (currently copied about 3 or 4 
different places in subclasses)? 
https://github.com/apache/lucene/blob/main/lucene/core/src/java/org/apache/lucene/search/similarities/Similarity.java#L114
   
   I wouldn't mess with any other method, except their javadocs. If we have a 
default implementation for `computeNorm` then we can suggest in these places a 
code snippet of how to decode it (e.g. link to SmallFloat.byte4ToInt or 
whatever) to help users:
   * 
https://github.com/apache/lucene/blob/main/lucene/core/src/java/org/apache/lucene/search/similarities/Similarity.java#L158
   * 
https://github.com/apache/lucene/blob/main/lucene/core/src/java/org/apache/lucene/search/similarities/Similarity.java#L167
   
   It would make the class easier to use. Users might look at BM25Similarity to 
try to figure out how to do it today, but that one has heavy optimizations such 
as precomputed length table. A couple javadocs would go a long way on the 
query-side there.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to