Ejemplo n.º 1
0
        public TokenStream GetTokenStream(Analyzer analyzer)
        {
            if (!((FieldType)FieldType()).Indexed)
            {
                return(null);
            }
            Number n = new Number();

            FieldType.NumericType?numericType = ((FieldType)FieldType()).NumericTypeValue;
            if (numericType != null)
            {
                if (!(InternalTokenStream is NumericTokenStream))
                {
                    // lazy init the TokenStream as it is heavy to instantiate
                    // (attributes,...) if not needed (stored field loading)
                    InternalTokenStream = new NumericTokenStream(Type.NumericPrecisionStep);
                }
                NumericTokenStream nts = (NumericTokenStream)InternalTokenStream;
                // initialize value in TokenStream
                object val = FieldsData;
                switch (numericType)
                {
                case Documents.FieldType.NumericType.INT:
                    nts.SetIntValue(Convert.ToInt32(val));
                    break;

                case Documents.FieldType.NumericType.LONG:
                    nts.SetLongValue(Convert.ToInt64(val));
                    break;

                case Documents.FieldType.NumericType.FLOAT:
                    nts.SetFloatValue(Convert.ToSingle(val));
                    break;

                case Documents.FieldType.NumericType.DOUBLE:
                    nts.SetDoubleValue(Convert.ToDouble(val));
                    break;

                default:
                    throw new Exception("Should never get here");
                }
                return(InternalTokenStream);
            }

            if (!((FieldType)FieldType()).Tokenized)
            {
                if (StringValue == null)
                {
                    throw new System.ArgumentException("Non-Tokenized Fields must have a String value");
                }
                if (!(InternalTokenStream is StringTokenStream))
                {
                    // lazy init the TokenStream as it is heavy to instantiate
                    // (attributes,...) if not needed (stored field loading)
                    InternalTokenStream = new StringTokenStream();
                }
                ((StringTokenStream)InternalTokenStream).Value = StringValue;
                return(InternalTokenStream);
            }

            if (TokenStream_Renamed != null)
            {
                return(TokenStream_Renamed);
            }
            else if (ReaderValue != null)
            {
                return(analyzer.TokenStream(Name(), ReaderValue));
            }
            else if (StringValue != null)
            {
                TextReader sr = new StringReader(StringValue);
                return(analyzer.TokenStream(Name(), sr));
            }

            throw new System.ArgumentException("Field must have either TokenStream, String, Reader or Number value; got " + this);
        }
Ejemplo n.º 2
0
 /// <summary> Initializes the field with the supplied <c>double</c> value.</summary>
 /// <param name="value_Renamed">the numeric value
 /// </param>
 /// <returns> this instance, because of this you can use it the following way:
 /// <c>document.add(new NumericField(name, precisionStep).setDoubleValue(value))</c>
 /// </returns>
 public NumericField SetDoubleValue(double value_Renamed)
 {
     tokenStream.SetDoubleValue(value_Renamed);
     fieldsData = value_Renamed;
     return(this);
 }