protected void AddField(string name, object value, AzureSearchFieldConfiguration fieldSettings, float boost = 0.0f) { Assert.IsNotNull((object)fieldSettings, "fieldSettings"); name = this.Index.FieldNameTranslator.GetIndexFieldName(name); boost += fieldSettings.Boost; IEnumerable enumerable = value as IEnumerable; if (enumerable != null && !(value is string)) { foreach (object valueToIndex in enumerable) { object obj = fieldSettings.FormatForWriting(valueToIndex); Field field = AzureFieldBuilder.CreateField(name, obj, fieldSettings, this.Index.Configuration.IndexFieldStorageValueFormatter); if (field != null) { //TODO: How to figure out boost //field.Boost = boost; this.fields.Enqueue(field); } } } else { value = fieldSettings.FormatForWriting(value); var field = AzureFieldBuilder.CreateField(name, value, fieldSettings, this.Index.Configuration.IndexFieldStorageValueFormatter); if (field == null) { return; } //TODO: How to figure out boost //field.Boost = boost; this.fields.Enqueue(field); } }
public static Field CreateField(string name, object value, AzureSearchFieldConfiguration fieldConfiguration, IIndexFieldStorageValueFormatter indexFieldStorageValueFormatter) { if (value == null) { VerboseLogging.CrawlingLogDebug((Func <string>)(() => string.Format("Skipping field {0} - value null", (object)name))); return((Field)null); } if (fieldConfiguration == null) { throw new ArgumentNullException("fieldConfiguration"); } if (VerboseLogging.Enabled) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendFormat("Field: {0}" + Environment.NewLine, (object)name); stringBuilder.AppendFormat(" - value: {0}" + Environment.NewLine, (object)value.GetType()); stringBuilder.AppendFormat(" - value: {0}" + Environment.NewLine, value); //stringBuilder.AppendFormat(" - fieldConfiguration analyzer: {0}" + Environment.NewLine, fieldConfiguration.Analyzer != null ? (object)fieldConfiguration.Analyzer.GetType().ToString() : (object)"NULL"); stringBuilder.AppendFormat(" - fieldConfiguration boost: {0}" + Environment.NewLine, (object)fieldConfiguration.Boost); stringBuilder.AppendFormat(" - fieldConfiguration fieldID: {0}" + Environment.NewLine, (object)fieldConfiguration.FieldID); stringBuilder.AppendFormat(" - fieldConfiguration FieldName: {0}" + Environment.NewLine, (object)fieldConfiguration.FieldName); stringBuilder.AppendFormat(" - fieldConfiguration FieldTypeName: {0}" + Environment.NewLine, (object)fieldConfiguration.FieldTypeName); //stringBuilder.AppendFormat(" - fieldConfiguration IndexType: {0}" + Environment.NewLine, (object)fieldConfiguration.IndexType); //stringBuilder.AppendFormat(" - fieldConfiguration StorageType: {0}" + Environment.NewLine, (object)fieldConfiguration.StorageType); //stringBuilder.AppendFormat(" - fieldConfiguration VectorType: {0}" + Environment.NewLine, (object)fieldConfiguration.VectorType); stringBuilder.AppendFormat(" - fieldConfiguration Type: {0}" + Environment.NewLine, (object)fieldConfiguration.Type); VerboseLogging.CrawlingLogDebug(new Func <string>(((object)stringBuilder).ToString)); } if (AzureFieldBuilder.IsNumericField(fieldConfiguration.Type)) { if (value is string && string.IsNullOrEmpty((string)value)) { VerboseLogging.CrawlingLogDebug((Func <string>)(() => string.Format("Skipping field {0} - value or empty null", (object)name))); return((Field)null); } long result; if (long.TryParse(value.ToString(), out result)) { var numericField = new Field(name, DataType.Int64); //TODO: How to set value? //numericField.((long)Convert.ChangeType(value, typeof(long))); return(numericField); } } if (AzureFieldBuilder.IsFloatingPointField(fieldConfiguration.Type)) { if (value is string && string.IsNullOrEmpty((string)value)) { VerboseLogging.CrawlingLogDebug((Func <string>)(() => string.Format("Skipping field {0} - value or empty null", (object)name))); return((Field)null); } var numericField = new Field(name, DataType.Double); //numericField.SetDoubleValue((double)Convert.ChangeType(value, typeof(double), (IFormatProvider)LanguageUtil.GetCultureInfo())); return((Field)numericField); } string value_Renamed = indexFieldStorageValueFormatter.FormatValueForIndexStorage(value, name).ToString(); if (VerboseLogging.Enabled) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendFormat("Field: {0}" + Environment.NewLine, (object)name); stringBuilder.AppendFormat(" - formattedValue: {0}" + Environment.NewLine, (object)value_Renamed); VerboseLogging.CrawlingLogDebug(new Func <string>(((object)stringBuilder).ToString)); } //TODO: How to set field value? return((Field) new Field(name, DataType.String /*, value_Renamed*/)); }