public static string GetAzureSearchType(IDocumentField field)
        {
            if (field.ContainsAttribute(IndexDataType.StringCollection))
            {
                return FieldType.StringCollection;
            }

            var type = field.Value != null ? field.Value.GetType() : typeof(String);
            return GetAzureSearchType(type);
        }
        public static string GetAzureSearchType(IDocumentField field)
        {
            if (field.ContainsAttribute(IndexDataType.StringCollection))
            {
                return(FieldType.StringCollection);
            }

            var type = field.Value != null?field.Value.GetType() : typeof(String);

            return(GetAzureSearchType(type));
        }
        public void Add(IDocumentField field)
        {
            var existingField = this[field.Name];

            if (existingField != null)
            {
                existingField.AddValue(field.Value);
            }
            else
            {
                _fields.Add(field);
            }
        }
Beispiel #4
0
        public void Add(IDocumentField field)
        {
            var existingField = this[field.Name];

            if (existingField != null)
            {
                existingField.AddValue(field.Value);
            }
            else
            {
                _fields.Add(field);
            }
        }
 public void RemoveField(string name)
 {
     System.Collections.IEnumerator it = _Fields.GetEnumerator();
     while (it.MoveNext())
     {
         IDocumentField field = (IDocumentField)it.Current;
         if (field.Name.Equals(name))
         {
             _Fields.Remove(field);
             return;
         }
     }
 }
        public bool ContainsKey(string name)
        {
            System.Collections.IEnumerator it = _Fields.GetEnumerator();
            while (it.MoveNext())
            {
                IDocumentField field = (IDocumentField)it.Current;
                if (field.Name.Equals(name))
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #7
0
 public void Add(IDocumentField field)
 {
     _Fields.Add(field);
 }
Beispiel #8
0
        /// <summary>
        ///     Adds the field to the lucene document.
        /// </summary>
        /// <param name="doc">The doc.</param>
        /// <param name="field">The field.</param>
        private static void AddFieldToDocument(ref Document doc, IDocumentField field)
        {
            if (field == null)
            {
                return;
            }

            var store = Field.Store.YES;
            var index = Field.Index.NOT_ANALYZED;

            if (field.ContainsAttribute(IndexStore.No))
            {
                store = Field.Store.NO;
            }

            if (field.ContainsAttribute(IndexType.Analyzed))
            {
                index = Field.Index.ANALYZED;
            }
            else if (field.ContainsAttribute(IndexType.No))
            {
                index = Field.Index.NO;
            }

            if (field.Value == null)
            {
                return;
            }

            field.Name = field.Name.ToLower();
            if (field.Name == "__key")
            {
                foreach (var val in field.Values)
                {
                    doc.Add(new Field(field.Name, val.ToString(), store, index));
                }
            }
            else if (field.Value is string)
            {
                foreach (var val in field.Values)
                {
                    doc.Add(new Field(field.Name, val.ToString(), store, index));
                    doc.Add(new Field("_content", val.ToString(), Field.Store.NO, Field.Index.ANALYZED));
                }
            }
            else if (field.Value is decimal) // parse prices
            {
                foreach (var val in field.Values)
                {
                    var numericField = new NumericField(field.Name, store, index != Field.Index.NO);
                    numericField.SetDoubleValue(double.Parse(val.ToString()));
                    doc.Add(numericField);
                }
            }
            else if (field.Value is DateTime) // parse dates
            {
                foreach (var val in field.Values)
                {
                    doc.Add(
                        new Field(
                            field.Name, DateTools.DateToString((DateTime)val, DateTools.Resolution.SECOND), store, index));
                }
            }
            else // try detecting the type
            {
                // TODO: instead of auto detecting, use meta data information
                decimal t;
                if (Decimal.TryParse(field.Value.ToString(), out t))
                {
                    foreach (var val in field.Values)
                    {
                        var numericField = new NumericField(field.Name, store, index != Field.Index.NO);
                        numericField.SetDoubleValue(double.Parse(val.ToString()));
                        doc.Add(numericField);
                    }
                }
                else
                {
                    foreach (var val in field.Values)
                    {
                        doc.Add(new Field(field.Name, val.ToString(), store, index));
                    }
                }
            }
        }
        /// <summary>
        ///     Adds the field to the lucene document.
        /// </summary>
        /// <param name="doc">The doc.</param>
        /// <param name="field">The field.</param>
        private static void AddFieldToDocument(ref Document doc, IDocumentField field)
        {
            if (field == null)
            {
                return;
            }

            var store = Field.Store.YES;
            var index = Field.Index.NOT_ANALYZED;

            if (field.ContainsAttribute(value: IndexStore.NO))
            {
                store = Field.Store.NO;
            }

            if (field.ContainsAttribute(IndexType.ANALYZED))
            {
                index = Field.Index.ANALYZED;
            }
            else if (field.ContainsAttribute(IndexType.NO))
            {
                index = Field.Index.NO;
            }

            if (field.Value == null)
            {
                return;
            }

            field.Name = field.Name.ToLower();
            if (field.Name == "__key")
            {
                foreach (var val in field.Values)
                {
                    doc.Add(new Field(field.Name, val.ToString(), store, index));
                }
            }
            else if (field.Value is string)
            {
                foreach (var val in field.Values)
                {
                    doc.Add(new Field(field.Name, val.ToString(), store, index));
                    doc.Add(new Field("_content", val.ToString(), Field.Store.NO, Field.Index.ANALYZED));
                }
            }
            else if (field.Value is decimal) // parse prices
            {
                foreach (var val in field.Values)
                {
                    var numericField = new NumericField(field.Name, store, index != Field.Index.NO);
                    numericField.SetDoubleValue(double.Parse(val.ToString()));
                    doc.Add(numericField);
                }
            }
            else if (field.Value is DateTime) // parse dates
            {
                foreach (var val in field.Values)
                {
                    doc.Add(
                        new Field(
                            field.Name, DateTools.DateToString((DateTime)val, DateTools.Resolution.SECOND), store, index));
                }
            }
            else // try detecting the type
            {
                // TODO: instead of auto detecting, use meta data information
                decimal t;
                if (Decimal.TryParse(field.Value.ToString(), out t))
                {
                    foreach (var val in field.Values)
                    {
                        var numericField = new NumericField(field.Name, store, index != Field.Index.NO);
                        numericField.SetDoubleValue(double.Parse(val.ToString()));
                        doc.Add(numericField);
                    }
                }
                else
                {
                    foreach (var val in field.Values)
                    {
                        doc.Add(new Field(field.Name, val.ToString(), store, index));
                    }
                }
            }
        }
 public void Add(IDocumentField field)
 {
     _Fields.Add(field);
 }