Пример #1
0
 public override void FinishDocument()
 {
     // append the payload bytes of the doc after its terms
     TermSuffixes.WriteBytes(PayloadBytes.Bytes, PayloadBytes.Length);
     PayloadBytes.Length = 0;
     ++NumDocs;
     if (TriggerFlush())
     {
         Flush();
     }
     CurDoc = null;
 }
Пример #2
0
 public override void AddPosition(int position, int startOffset, int endOffset, BytesRef payload)
 {
     Debug.Assert(CurField.Flags != 0);
     CurField.AddPosition(position, startOffset, endOffset - startOffset, payload == null ? 0 : payload.Length);
     if (CurField.HasPayloads && payload != null)
     {
         PayloadBytes.WriteBytes(payload.Bytes, payload.Offset, payload.Length);
     }
 }
Пример #3
0
 public override void AddPosition(int position, int startOffset, int endOffset, BytesRef payload)
 {
     if (Debugging.AssertsEnabled)
     {
         Debugging.Assert(curField.flags != 0);
     }
     curField.AddPosition(position, startOffset, endOffset - startOffset, payload == null ? 0 : payload.Length);
     if (curField.hasPayloads && payload != null)
     {
         payloadBytes.WriteBytes(payload.Bytes, payload.Offset, payload.Length);
     }
 }
Пример #4
0
 internal virtual void WriteSequence()
 {
     Debug.Assert(SequenceIsConsistent());
     try
     {
         WriteHeader(reverse, clean, dirtyWords.Length);
     }
     catch (IOException cannotHappen)
     {
         throw new InvalidOperationException(cannotHappen.ToString(), cannotHappen); // LUCENENET NOTE: This was AssertionError in Lucene
     }
     @out.WriteBytes(dirtyWords.Bytes, 0, dirtyWords.Length);
     dirtyWords.Length = 0;
     ++numSequences;
 }
Пример #5
0
        public override void WriteField(FieldInfo info, IIndexableField field)
        {
            int      bits /* = 0*/; // LUCENENET: IDE0059: Remove unnecessary value assignment
            BytesRef bytes;
            string   @string;

            // LUCENENET specific - To avoid boxing/unboxing, we don't
            // call GetNumericValue(). Instead, we check the field.NumericType and then
            // call the appropriate conversion method.
            if (field.NumericType != NumericFieldType.NONE)
            {
                switch (field.NumericType)
                {
                case NumericFieldType.BYTE:
                case NumericFieldType.INT16:
                case NumericFieldType.INT32:
                    bits = NUMERIC_INT32;
                    break;

                case NumericFieldType.INT64:
                    bits = NUMERIC_INT64;
                    break;

                case NumericFieldType.SINGLE:
                    bits = NUMERIC_SINGLE;
                    break;

                case NumericFieldType.DOUBLE:
                    bits = NUMERIC_DOUBLE;
                    break;

                default:
                    throw new ArgumentException("cannot store numeric type " + field.NumericType);
                }

                @string = null;
                bytes   = null;
            }
            else
            {
                bytes = field.GetBinaryValue();
                if (bytes != null)
                {
                    bits    = BYTE_ARR;
                    @string = null;
                }
                else
                {
                    bits    = STRING;
                    @string = field.GetStringValue();
                    if (@string == null)
                    {
                        throw new ArgumentException("field " + field.Name + " is stored but does not have BinaryValue, StringValue nor NumericValue");
                    }
                }
            }

            long infoAndBits = (((long)info.Number) << TYPE_BITS) | (uint)bits;

            bufferedDocs.WriteVInt64(infoAndBits);

            if (bytes != null)
            {
                bufferedDocs.WriteVInt32(bytes.Length);
                bufferedDocs.WriteBytes(bytes.Bytes, bytes.Offset, bytes.Length);
            }
            else if (@string != null)
            {
                bufferedDocs.WriteString(field.GetStringValue());
            }
            else
            {
                switch (field.NumericType)
                {
                case NumericFieldType.BYTE:
                case NumericFieldType.INT16:
                case NumericFieldType.INT32:
                    bufferedDocs.WriteInt32(field.GetInt32Value().Value);
                    break;

                case NumericFieldType.INT64:
                    bufferedDocs.WriteInt64(field.GetInt64Value().Value);
                    break;

                case NumericFieldType.SINGLE:
                    bufferedDocs.WriteInt32(BitConversion.SingleToInt32Bits(field.GetSingleValue().Value));
                    break;

                case NumericFieldType.DOUBLE:
                    bufferedDocs.WriteInt64(BitConversion.DoubleToInt64Bits(field.GetDoubleValue().Value));
                    break;

                default:
                    throw AssertionError.Create("Cannot get here");
                }
            }
        }
        public override void WriteField(FieldInfo info, IndexableField field)
        {
            int      bits = 0;
            BytesRef bytes;
            string   @string;

            object number = (object)field.NumericValue;

            if (number != null)
            {
                if (number is string)
                {
                    string numStr = number.ToString();
                    sbyte  dummySbyte;
                    short  dummyShort;
                    int    dummyInt;
                    long   dummyLong;
                    float  dummyFloat;
                    double dummyDouble;
                    if (sbyte.TryParse(numStr, out dummySbyte) || short.TryParse(numStr, out dummyShort) || int.TryParse(numStr, out dummyInt))
                    {
                        bits = NUMERIC_INT;
                    }
                    else if (long.TryParse(numStr, out dummyLong))
                    {
                        bits = NUMERIC_LONG;
                    }
                    else if (float.TryParse(numStr, out dummyFloat))
                    {
                        bits = NUMERIC_FLOAT;
                    }
                    else if (double.TryParse(numStr, out dummyDouble))
                    {
                        bits = NUMERIC_DOUBLE;
                    }
                    else
                    {
                        throw new System.ArgumentException("cannot store numeric type " + number.GetType());
                    }
                }
                else
                {
                    if (number is sbyte || number is short || number is int)
                    {
                        bits = NUMERIC_INT;
                    }
                    else if (number is long)
                    {
                        bits = NUMERIC_LONG;
                    }
                    else if (number is float)
                    {
                        bits = NUMERIC_FLOAT;
                    }
                    else if (number is double)
                    {
                        bits = 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    = BYTE_ARR;
                    @string = null;
                }
                else
                {
                    bits    = STRING;
                    @string = field.StringValue;
                    if (@string == null)
                    {
                        throw new System.ArgumentException("field " + field.Name() + " is stored but does not have binaryValue, stringValue nor numericValue");
                    }
                }
            }

            long infoAndBits = (((long)info.Number) << TYPE_BITS) | bits;

            BufferedDocs.WriteVLong(infoAndBits);

            if (bytes != null)
            {
                BufferedDocs.WriteVInt(bytes.Length);
                BufferedDocs.WriteBytes(bytes.Bytes, bytes.Offset, bytes.Length);
            }
            else if (@string != null)
            {
                BufferedDocs.WriteString(field.StringValue);
            }
            else
            {
                if (number is string)
                {
                    string numStr = number.ToString();
                    sbyte  dummySbyte;
                    short  dummyShort;
                    int    dummyInt;
                    long   dummyLong;
                    float  dummyFloat;
                    double dummyDouble;
                    if (sbyte.TryParse(numStr, out dummySbyte) || short.TryParse(numStr, out dummyShort) ||
                        int.TryParse(numStr, out dummyInt))
                    {
                        bits = NUMERIC_INT;
                    }
                    else if (long.TryParse(numStr, out dummyLong))
                    {
                        bits = NUMERIC_LONG;
                    }
                    else if (float.TryParse(numStr, out dummyFloat))
                    {
                        bits = NUMERIC_FLOAT;
                    }
                    else if (double.TryParse(numStr, out dummyDouble))
                    {
                        bits = NUMERIC_DOUBLE;
                    }
                    else
                    {
                        throw new System.ArgumentException("cannot store numeric type " + number.GetType());
                    }
                }
                else
                {
                    if (number is sbyte || number is short || number is int)
                    {
                        BufferedDocs.WriteInt((int)number);
                    }
                    else if (number is long)
                    {
                        BufferedDocs.WriteLong((long)number);
                    }
                    else if (number is float)
                    {
                        BufferedDocs.WriteInt(Number.FloatToIntBits((float)number));
                    }
                    else if (number is double)
                    {
                        BufferedDocs.WriteLong(BitConverter.DoubleToInt64Bits((double)number));
                    }
                    else
                    {
                        throw new Exception("Cannot get here");
                    }
                }
            }
        }