Skip to content

Apache Lucene open-source search software

Expose the ImpactsEnum impl in Lucene101PostingsFormat. (#14306)

Adrien Grandbe3e39d2c80e
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene101/Lucene101PostingsFormat.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene101/Lucene101PostingsFormat.java
index d83111bb8fe..a2441a9e486 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene101/Lucene101PostingsFormat.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene101/Lucene101PostingsFormat.java
@@ -26,6 +26,7 @@ import org.apache.lucene.codecs.PostingsReaderBase;
import org.apache.lucene.codecs.PostingsWriterBase;
import org.apache.lucene.codecs.lucene90.blocktree.Lucene90BlockTreeTermsReader;
import org.apache.lucene.codecs.lucene90.blocktree.Lucene90BlockTreeTermsWriter;
+import org.apache.lucene.index.ImpactsEnum;
import org.apache.lucene.index.IndexOptions;
import org.apache.lucene.index.SegmentReadState;
import org.apache.lucene.index.SegmentWriteState;
@@ -351,6 +352,14 @@ public final class Lucene101PostingsFormat extends PostingsFormat {
public static final int LEVEL1_MASK = LEVEL1_NUM_DOCS - 1;
+ /**
+ * Return the class that implements {@link ImpactsEnum} in this {@link PostingsFormat}. This is
+ * internally used to help the JVM make good inlining decisions.
+ */
+ public static Class<? extends ImpactsEnum> getImpactsEnumImpl() {
+ return Lucene101PostingsReader.BlockPostingsEnum.class;
+ }
+
static final String TERMS_CODEC = "Lucene90PostingsWriterTerms";
static final String META_CODEC = "Lucene101PostingsWriterMeta";
static final String DOC_CODEC = "Lucene101PostingsWriterDoc";
diff --git a/lucene/core/src/java/org/apache/lucene/search/ScorerUtil.java b/lucene/core/src/java/org/apache/lucene/search/ScorerUtil.java
index 2f0e5c6ade8..de304ea2722 100644
--- a/lucene/core/src/java/org/apache/lucene/search/ScorerUtil.java
+++ b/lucene/core/src/java/org/apache/lucene/search/ScorerUtil.java
@@ -16,52 +16,21 @@
*/
package org.apache.lucene.search;
-import java.io.IOException;
import java.util.stream.LongStream;
import java.util.stream.StreamSupport;
-import org.apache.lucene.document.Document;
-import org.apache.lucene.document.FeatureField;
-import org.apache.lucene.index.DirectoryReader;
+import org.apache.lucene.codecs.lucene101.Lucene101PostingsFormat;
import org.apache.lucene.index.ImpactsEnum;
-import org.apache.lucene.index.IndexWriter;
-import org.apache.lucene.index.IndexWriterConfig;
-import org.apache.lucene.index.LeafReader;
-import org.apache.lucene.index.PostingsEnum;
-import org.apache.lucene.index.TermsEnum;
-import org.apache.lucene.store.ByteBuffersDirectory;
-import org.apache.lucene.store.Directory;
import org.apache.lucene.util.Bits;
-import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.FixedBitSet;
import org.apache.lucene.util.PriorityQueue;
/** Util class for Scorer related methods */
class ScorerUtil {
- private static final Class<?> DEFAULT_IMPACTS_ENUM_CLASS;
- private static final Class<?> DEFAULT_ACCEPT_DOCS_CLASS;
-
- static {
- try (Directory dir = new ByteBuffersDirectory();
- IndexWriter w = new IndexWriter(dir, new IndexWriterConfig())) {
- Document doc = new Document();
- doc.add(new FeatureField("field", "value", 1f));
- w.addDocument(doc);
- try (DirectoryReader reader = DirectoryReader.open(w)) {
- LeafReader leafReader = reader.leaves().get(0).reader();
- TermsEnum te = leafReader.terms("field").iterator();
- if (te.seekExact(new BytesRef("value")) == false) {
- throw new Error();
- }
- ImpactsEnum ie = te.impacts(PostingsEnum.FREQS);
- DEFAULT_IMPACTS_ENUM_CLASS = ie.getClass();
- }
- } catch (IOException e) {
- throw new Error(e);
- }
-
- DEFAULT_ACCEPT_DOCS_CLASS = new FixedBitSet(1).asReadOnlyBits().getClass();
- }
+ private static final Class<?> DEFAULT_IMPACTS_ENUM_CLASS =
+ Lucene101PostingsFormat.getImpactsEnumImpl();
+ private static final Class<?> DEFAULT_ACCEPT_DOCS_CLASS =
+ new FixedBitSet(1).asReadOnlyBits().getClass();
static long costWithMinShouldMatch(LongStream costs, int numScorers, int minShouldMatch) {
// the idea here is the following: a boolean query c1,c2,...cn with minShouldMatch=m