/// <summary> /// Writes a single stored field. </summary> public abstract void WriteField(FieldInfo info, IndexableField field);
public override void WriteField(FieldInfo info, IndexableField field) { Debug.Assert(DocStatus == Status.STARTED); @in.WriteField(info, field); Debug.Assert(FieldCount > 0); FieldCount--; }
public override void WriteField(FieldInfo info, IndexableField field) { FieldsStream.WriteVInt(info.Number); int bits = 0; BytesRef bytes; string @string; // TODO: maybe a field should serialize itself? // this way we don't bake into indexer all these // specific encodings for different fields? and apps // can customize... object number = field.NumericValue; if (number != null) { if (number is sbyte? || number is short? || number is int?) { bits |= Lucene3xStoredFieldsReader.FIELD_IS_NUMERIC_INT; } else if (number is long?) { bits |= Lucene3xStoredFieldsReader.FIELD_IS_NUMERIC_LONG; } else if (number is float?) { bits |= Lucene3xStoredFieldsReader.FIELD_IS_NUMERIC_FLOAT; } else if (number is double?) { bits |= Lucene3xStoredFieldsReader.FIELD_IS_NUMERIC_DOUBLE; } else { throw new System.ArgumentException("cannot store numeric type " + number.GetType()); } @string = null; bytes = null; } else { bytes = field.BinaryValue(); if (bytes != null) { bits |= Lucene3xStoredFieldsReader.FIELD_IS_BINARY; @string = null; } else { @string = field.StringValue; if (@string == null) { throw new System.ArgumentException("field " + field.Name() + " is stored but does not have binaryValue, stringValue nor numericValue"); } } } FieldsStream.WriteByte((byte)(sbyte)bits); if (bytes != null) { FieldsStream.WriteVInt(bytes.Length); FieldsStream.WriteBytes(bytes.Bytes, bytes.Offset, bytes.Length); } else if (@string != null) { FieldsStream.WriteString(field.StringValue); } else { if (number is sbyte? || number is short? || number is int?) { FieldsStream.WriteInt((int)number); } else if (number is long?) { FieldsStream.WriteLong((long)number); } else if (number is float?) { FieldsStream.WriteInt(Number.FloatToIntBits((float)number)); } else if (number is double?) { FieldsStream.WriteLong(BitConverter.DoubleToInt64Bits((double)number)); } else { Debug.Assert(false); } } }