private IEnumerable <AbstractField> GetOrCreateNumericField(IndexField field, object value, Field.Store storage, Field.TermVector termVector = Field.TermVector.NO) { var fieldName = field.Name + Constants.Indexing.Fields.RangeFieldSuffix; var cacheKey = new FieldCacheKey(field.Name, null, storage, termVector, _multipleItemsSameFieldCount.ToArray()); NumericField numericField; CachedFieldItem <NumericField> cached; if (_numericFieldsCache.TryGetValue(cacheKey, out cached) == false) { _numericFieldsCache[cacheKey] = cached = new CachedFieldItem <NumericField> { Field = numericField = new NumericField(CreateFieldName(fieldName), storage, true) }; } else { numericField = cached.Field; } double doubleValue; long longValue; switch (BlittableNumber.Parse(value, out doubleValue, out longValue)) { case NumberParseResult.Double: if (field.SortOption == SortOptions.NumericLong) { yield return(numericField.SetLongValue((long)doubleValue)); } else { yield return(numericField.SetDoubleValue(doubleValue)); } break; case NumberParseResult.Long: if (field.SortOption == SortOptions.NumericDouble) { yield return(numericField.SetDoubleValue(longValue)); } else { yield return(numericField.SetLongValue(longValue)); } break; } }
protected Field GetOrCreateField(string name, string value, LazyStringValue lazyValue, BlittableJsonReaderObject blittableValue, Field.Store store, Field.Index index, Field.TermVector termVector) { int cacheKey = FieldCacheKey.GetHashCode(name, index, store, termVector, _multipleItemsSameFieldCount); Field field; if (_fieldsCache.TryGetValue(cacheKey, out CachedFieldItem<Field> cached) == false || !cached.Key.IsSame(name, index, store, termVector, _multipleItemsSameFieldCount)) { LazyStringReader stringReader = null; BlittableObjectReader blittableReader = null; if ((lazyValue != null || blittableValue != null) && store.IsStored() == false && index.IsIndexed() && index.IsAnalyzed()) { TextReader reader; if (lazyValue != null) { stringReader = new LazyStringReader(); reader = stringReader.GetTextReaderFor(lazyValue); } else { blittableReader = Scope.GetBlittableReader(); reader = blittableReader.GetTextReaderFor(blittableValue); } field = new Field(name, reader, termVector); } else { if (value == null && lazyValue == null) blittableReader = Scope.GetBlittableReader(); field = new Field(name, value ?? LazyStringReader.GetStringFor(lazyValue) ?? blittableReader.GetStringFor(blittableValue), store, index, termVector); } field.Boost = 1; field.OmitNorms = true; _fieldsCache[cacheKey] = new CachedFieldItem<Field> { Key = new FieldCacheKey(name, index, store, termVector, _multipleItemsSameFieldCount.ToArray()), Field = field, LazyStringReader = stringReader }; } else { BlittableObjectReader blittableReader = null; field = cached.Field; if (lazyValue != null && cached.LazyStringReader == null) cached.LazyStringReader = new LazyStringReader(); if (blittableValue != null) blittableReader = Scope.GetBlittableReader(); if ((lazyValue != null || blittableValue != null) && store.IsStored() == false && index.IsIndexed() && index.IsAnalyzed()) { field.SetValue(lazyValue != null ? cached.LazyStringReader.GetTextReaderFor(lazyValue) : blittableReader.GetTextReaderFor(blittableValue)); } else { field.SetValue(value ?? LazyStringReader.GetStringFor(lazyValue) ?? blittableReader.GetStringFor(blittableValue)); } } return field; }