Exemple #1
0
        public static void FieldAssert(FieldMapping expected, FieldMapping actual)
        {
            Assert.AreEqual(expected.FieldName, actual.FieldName);
            Assert.AreEqual(expected.Boost, actual.Boost);
            Assert.AreEqual(expected.AnalyzerType, actual.AnalyzerType);
            Assert.AreEqual(expected.IsNumeric, actual.IsNumeric);
            Assert.AreEqual(expected.IsRequired, actual.IsRequired);
            Assert.AreEqual(expected.Index, actual.Index);
            Assert.AreEqual(expected.Store, actual.Store);

            MemberAssert(expected.Member, actual.Member);
        }
Exemple #2
0
 private static IEnumerable<AbstractField> GetFieldsInternal(FieldMapping mapping, Object value, string fieldName, string prefix)
 {
     if (IsPrimitive(value))
         return new AbstractField[] { CreateField(mapping, value, prefix + fieldName) };
     else if (value is IEnumerable)
         return CreateEnumerableField(mapping, value as IEnumerable, fieldName, prefix);
     else if (value is KeyValuePair<string, object>)
         return CreateField(mapping, (KeyValuePair<string, object>)value, prefix);
     else
         throw new ArgumentException(
             String.Format(Properties.Resources.EXC_FIELD_MAPPING_TYPE_NOT_SUPPORTED, value.GetType()));
 }
        public virtual void SetUp()
        {
            var memberMock = Substitute.For<Member>();
            memberMock.CanWrite.Returns(true);
            memberMock.MemberType.Returns(typeof(string));

            var extendedMemberMock = Substitute.For<Member>();
            extendedMemberMock.CanWrite.Returns(true);
            extendedMemberMock.MemberType.Returns(typeof(string));

            FieldConfiguration = new FieldConfiguration("FieldName", memberMock);
            ExpectedFieldMapping = new FieldConfiguration("FieldName", extendedMemberMock).GetMapping();
        }
Exemple #4
0
        private static AbstractField CreateNumericField(FieldMapping mapping, ValueType value, string fieldName)
        {
            NumericField numField = new NumericField(
                    fieldName, DefaultPrecisionStep,
                    mapping.Store, mapping.Index != Field.Index.NO);

            if (value is int)
                numField.SetIntValue((int)value);
            else if (value is long)
                numField.SetLongValue((long)value);
            else if (value is float)
                numField.SetFloatValue((float)value);
            else if (value is double)
                numField.SetDoubleValue((double)value);
            else if (value is decimal)
                numField.SetDoubleValue((double)(decimal)value);
            else if (value is DateTime)
                numField.SetLongValue(((DateTime)value).ToBinary());
            else
                throw new Exception(String.Format(Properties.Resources.EXC_TYPE_NOT_SUPPORTED, value));

            return numField;
        }
Exemple #5
0
 private static IEnumerable<AbstractField> CreateField(FieldMapping mapping, KeyValuePair<string, object> pair, string prefix)
 {
     return GetFieldsInternal(mapping, pair.Value, pair.Key, prefix);
 }
Exemple #6
0
        private static AbstractField CreateField(FieldMapping mapping, object value, string fieldName)
        {
            if (mapping.IsNumeric)
            {
                return CreateNumericField(mapping, (ValueType)value, fieldName);
            }
            else
            {
                string strValue = (value is IFormattable) ?
                        ((IFormattable)value).ToString(null, StringFormat) : value.ToString();

                return new Field(fieldName, strValue, mapping.Store, mapping.Index);
            }
        }
Exemple #7
0
        private static IEnumerable<AbstractField> CreateEnumerableField(FieldMapping mapping, IEnumerable values, string fieldName, string prefix)
        {
            List<AbstractField> fields = new List<AbstractField>();
            foreach (object obj in values)
            {
                fields.AddRange(GetFieldsInternal(mapping, obj, fieldName, prefix));
            }

            return fields;
        }
Exemple #8
0
        /// <summary>
        /// Returns the field collection by the specified field mapping and object.
        /// </summary>
        /// <param name="mapping">The field mapping to convert an object into a set of fields.</param>
        /// <param name="value">An object for which to get a set of fields.</param>
        /// <param name="prefix">A <see cref="System.String"/> representing the prefix for the all field names.</param>
        /// <returns>set of fields for document.</returns>
        public static IEnumerable<IFieldable> GetFields(FieldMapping mapping, Object value, string prefix)
        {
            if (value == null) return null;

            IEnumerable<AbstractField> fields = GetFieldsInternal(mapping, value, mapping.FieldName, prefix);

            if (mapping.Boost.HasValue)
            {
                foreach (AbstractField field in fields)
                {
                    field.Boost = mapping.Boost.Value;
                }
            }

            return fields;
        }