Exemple #1
0
        public void Add(PropertyInfo property, string fieldName, float?boost)
        {
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }
            if (fieldName == null)
            {
                throw new ArgumentNullException("fieldName");
            }

            var fld = new SolrFieldModel {
                Property = property, FieldName = fieldName, Boost = boost
            };

            var t = property.ReflectedType;

            if (!mappings.ContainsKey(t))
            {
                mappings[t] = new Dictionary <string, SolrFieldModel>();
            }

            var m = mappings[t].FirstOrDefault(k => k.Value.Property == property);

            if (m.Key != null)
            {
                mappings[t].Remove(m.Key);
            }


            mappings[t][fieldName] = fld;
        }
Exemple #2
0
        public void Add(PropertyInfo property, string fieldName, float? boost)
        {
            if (property == null)
                throw new ArgumentNullException("property");
            if (fieldName == null)
                throw new ArgumentNullException("fieldName");

            var fld = new SolrFieldModel {Property = property, FieldName = fieldName, Boost = boost};

            var t = property.ReflectedType;

            if (!mappings.ContainsKey(t))
            {
                mappings[t] = new List<SolrFieldModel>();
            }

            var idx = mappings[t].FindIndex(f => f.Property == fld.Property);

            if(idx >= 0)
            {
                mappings[t][idx] = fld;
                return;
            }

            mappings[t].Add(fld);
        }
        public void InvalidCastReportsFieldName() {
            var mapper = new MReadOnlyMappingManager();
            mapper.getFields += type => {
                Assert.AreEqual(typeof (Entity), type);
                var model = new SolrFieldModel (
                    fieldName : "id",
                    property : typeof (Entity).GetProperty("Id"));
                return new Dictionary<string, SolrFieldModel> {
                    {"Id", model}
                };
            };
            mapper.getFields &= x => x.Expect(1);

            var parser = new MSolrFieldParser {
                canHandleSolrType = _ => true,
                canHandleType = _ => true,
                parse = (a,b) => "something",
            };

            var v = new RegularDocumentVisitor(parser, mapper);
            var doc = new Entity();
            var field = new XElement("tag");
            try {
                v.Visit(doc, "Id", field);
                Assert.Fail("Should have failed with invalid cast");
            } catch (ArgumentException e) {
                Assert.Contains(e.Message, "property 'Id'");
                Console.WriteLine(e.Message);
            }

            mapper.getFields.Verify();
        }
	    public void Add(PropertyInfo property, string fieldName, float? boost) {
		    if (property == null)
			    throw new ArgumentNullException("property");
		    if (fieldName == null)
			    throw new ArgumentNullException("fieldName");

			var declaringType = property.DeclaringType ?? property.ReflectedType;

			// create or find the SolrFieldModel dictionary...
		    Dictionary<string, SolrFieldModel> solrFieldDict;
			if (!mappings.ContainsKey(declaringType))
			{
			    solrFieldDict = new Dictionary<string, SolrFieldModel>();
				mappings[declaringType] = solrFieldDict;
		    } else {
				solrFieldDict = mappings[declaringType];
		    }

			// see if the property is already there...
			var m = solrFieldDict.FirstOrDefault(k => k.Value.Property == property);
		    if (m.Key != null) {
				// it is, so remove it
				solrFieldDict.Remove(m.Key);
		    }

			// and add the SolrFieldModel to the dictionary by fieldName
		    var fld = new SolrFieldModel(property, fieldName, boost);
			solrFieldDict[fieldName] = fld;
	    }
Exemple #5
0
        public void InvalidCastReportsFieldName()
        {
            var mapper = new MReadOnlyMappingManager();

            mapper.getFields += type => {
                Assert.AreEqual(typeof(Entity), type);
                var model = new SolrFieldModel(
                    fieldName: "id",
                    property: typeof(Entity).GetProperty("Id"));
                return(new Dictionary <string, SolrFieldModel> {
                    { "Id", model }
                });
            };
            mapper.getFields &= x => x.Expect(1);

            var parser = new MSolrFieldParser {
                canHandleSolrType = _ => true,
                canHandleType     = _ => true,
                parse             = (a, b) => "something",
            };

            var v     = new RegularDocumentVisitor(parser, mapper);
            var doc   = new Entity();
            var field = new XElement("tag");

            try {
                v.Visit(doc, "Id", field);
                Assert.Fail("Should have failed with invalid cast");
            } catch (ArgumentException e) {
                Assert.True(e.Message.Contains("property 'Id'"));
                Console.WriteLine(e.Message);
            }

            mapper.getFields.Verify();
        }
Exemple #6
0
        public void Add(PropertyInfo property, string fieldName, float?boost)
        {
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }
            if (fieldName == null)
            {
                throw new ArgumentNullException("fieldName");
            }

            var fld = new SolrFieldModel {
                Property = property, FieldName = fieldName, Boost = boost
            };

            var t = property.ReflectedType;

            if (!mappings.ContainsKey(t))
            {
                mappings[t] = new List <SolrFieldModel>();
            }

            var idx = mappings[t].FindIndex(f => f.Property == fld.Property);

            if (idx >= 0)
            {
                mappings[t][idx] = fld;
                return;
            }

            mappings[t].Add(fld);
        }
        public virtual string GetMemberSolrName(MemberInfo info)
        {
            return(MemberNames.GetOrAdd(info, m =>
            {
                var att = this.MappingManager.GetFields(info.DeclaringType);

                SolrFieldModel value = att.Values.FirstOrDefault(f => f.Property == info as PropertyInfo);
                if (value != null)
                {
                    return value.FieldName;
                }

                throw new InvalidOperationException(
                    $"Unable to get solr name for {m.DeclaringType}.{m.Name}. Mapping manager has mappings only for {string.Join(", ", att.Values.Select(f => f.Property.Name))}");
            }));
        }
        public void Add(PropertyInfo property, string fieldName, float?boost, bool useReflectedTypeOnly)
        {
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }
            if (fieldName == null)
            {
                throw new ArgumentNullException("fieldName");
            }

            var declaringType = useReflectedTypeOnly
                ? property.ReflectedType
                : property.DeclaringType ?? property.ReflectedType;

            // create or find the SolrFieldModel dictionary...
            Dictionary <string, SolrFieldModel> solrFieldDict;

            if (!mappings.ContainsKey(declaringType))
            {
                solrFieldDict           = new Dictionary <string, SolrFieldModel>();
                mappings[declaringType] = solrFieldDict;
            }
            else
            {
                solrFieldDict = mappings[declaringType];
            }

            // see if the property is already there...
            var m = solrFieldDict.FirstOrDefault(k => k.Value.Property == property);

            if (m.Key != null)
            {
                // it is, so remove it
                solrFieldDict.Remove(m.Key);
            }

            // and add the SolrFieldModel to the dictionary by fieldName
            var fld = new SolrFieldModel(property, fieldName, boost);

            solrFieldDict[fieldName] = fld;
        }
Exemple #9
0
        public void Add(PropertyInfo property, string fieldName, float? boost)
        {
            if (property == null)
                throw new ArgumentNullException("property");
            if (fieldName == null)
                throw new ArgumentNullException("fieldName");

            var fld = new SolrFieldModel {Property = property, FieldName = fieldName, Boost = boost};

            var t = property.ReflectedType;

            if (!mappings.ContainsKey(t)) {
                mappings[t] = new Dictionary<string,SolrFieldModel>();
            }

            var m = mappings[t].FirstOrDefault(k => k.Value.Property == property);
            if (m.Key != null) {
                mappings[t].Remove(m.Key);
            }

            mappings[t][fieldName] = fld;
        }