Skip to content

Apache Lucene open-source search software

LUCENE-4055: Refactor SegmentInfo and FieldInfo to make them extensible

Robert Muire9bb48725216
diff --cc lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/DocValuesWriterBase.java
index 83d3dc5a4c7,146342161bd..22c365539b0
--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/DocValuesWriterBase.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/DocValuesWriterBase.java
@@@ -63,17 -62,15 +63,17 @@@ public abstract class DocValuesWriterBa
/**
* @param state The state to initiate a {@link PerDocConsumer} instance
- * @param fasterButMoreRam whether packed ints for docvalues should be optimized for speed by rounding up the bytes
- * used for a value to either 8, 16, 32 or 64 bytes. This option is only applicable for
- * docvalues of type {@link Type#BYTES_FIXED_SORTED} and {@link Type#BYTES_VAR_SORTED}.
+ * @param acceptableOverheadRatio
+ * how to trade space for speed. This option is only applicable for
+ * docvalues of type {@link Type#BYTES_FIXED_SORTED} and
+ * {@link Type#BYTES_VAR_SORTED}.
+ * @see PackedInts#getReader(org.apache.lucene.store.DataInput)
*/
- protected DocValuesWriterBase(PerDocWriteState state, boolean fasterButMoreRam) {
+ protected DocValuesWriterBase(PerDocWriteState state, float acceptableOverheadRatio) {
- this.segmentName = state.segmentName;
+ this.segmentName = state.segmentInfo.name;
this.bytesUsed = state.bytesUsed;
this.context = state.context;
- this.fasterButMoreRam = fasterButMoreRam;
+ this.acceptableOverheadRatio = acceptableOverheadRatio;
}
protected abstract Directory getDirectory() throws IOException;
diff --cc lucene/test-framework/src/java/org/apache/lucene/util/_TestUtil.java
index f724b278ae8,7d58802d40b..adb35952499
--- a/lucene/test-framework/src/java/org/apache/lucene/util/_TestUtil.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/util/_TestUtil.java
@@@ -903,23 -898,24 +900,44 @@@ public class _TestUtil
}
}
+ public static FieldInfos getFieldInfos(SegmentInfo info) throws IOException {
+ Directory cfsDir = null;
+ try {
+ if (info.getUseCompoundFile()) {
+ cfsDir = new CompoundFileDirectory(info.dir,
+ IndexFileNames.segmentFileName(info.name, "", IndexFileNames.COMPOUND_FILE_EXTENSION),
+ IOContext.READONCE,
+ false);
+ } else {
+ cfsDir = info.dir;
+ }
+ return info.getCodec().fieldInfosFormat().getFieldInfosReader().read(cfsDir,
+ info.name,
+ IOContext.READONCE);
+ } finally {
+ if (info.getUseCompoundFile() && cfsDir != null) {
+ cfsDir.close();
+ }
+ }
+ }
++
+ /**
+ * Returns a valid (compiling) Pattern instance with random stuff inside. Be careful
+ * when applying random patterns to longer strings as certain types of patterns
+ * may explode into exponential times in backtracking implementations (such as Java's).
+ */
+ public static Pattern randomPattern(Random random) {
+ final String nonBmpString = "AB\uD840\uDC00C";
+ while (true) {
+ try {
+ Pattern p = Pattern.compile(_TestUtil.randomRegexpishString(random));
+ // Make sure the result of applying the pattern to a string with extended
+ // unicode characters is a valid utf16 string. See LUCENE-4078 for discussion.
+ if (UnicodeUtil.validUTF16String(p.matcher(nonBmpString).replaceAll("_")))
+ return p;
+ } catch (PatternSyntaxException ignored) {
+ // Loop trying until we hit something that compiles.
+ }
+ }
+ }
}