public ValidationResult Validate(SolrFieldType solrFieldType, string propertyName, Type propertyType) {
     if (new[] { "solr.TextField", "solr.StrField" }.Any(st => st == solrFieldType.Type))
         return new ValidationWarning(String.Format("Property '{0}' of type '{1}' is mapped to a solr field of type '{2}'. These types are not fully compatible. You won't be able to use this field for range queries.", propertyName, propertyType.FullName, solrFieldType.Name));
     if (new[] {"FloatField", "DoubleField"}.Any(st => Regex.IsMatch(solrFieldType.Type, st)))
         return new ValidationWarning(String.Format("Property '{0}' of type '{1}' is mapped to a solr field of type '{2}'. These types are not fully compatible. You might lose precision or get OverflowExceptions", propertyName, propertyType.FullName, solrFieldType.Name));
     return new ValidationError(String.Format("Property '{0}' of type '{1}' cannot be stored in solr field type '{2}'.", propertyName, propertyType.FullName, solrFieldType.Name));
 }
Esempio n. 2
0
 /// <summary>
 /// Repesents a field in the Solr schema.
 /// </summary>
 /// <param name="name">Field name</param>
 /// <param name="type">Field type</param>
 public SolrField(string name, SolrFieldType type) {
     if (name == null)
         throw new ArgumentNullException("name");
     if (type == null)
         throw new ArgumentNullException("type");
     Name = name;
     Type = type;
 } 
        public virtual ValidationResult Validate(SolrFieldType solrFieldType, string propertyName, Type propertyType) {
            // Check if the type is in the safe or warning types and otherwise return a error
            if (safeTypes != null && safeTypes.Contains(solrFieldType.Type))
                return null;
            if (warningTypes != null && warningTypes.Contains(solrFieldType.Type))
                return new ValidationWarning(String.Format("Property '{0}' of type '{1}' is mapped to a solr field of type '{2}'. These types are not fully compatible.", propertyName, propertyType.FullName, solrFieldType.Name));

            return new ValidationError(String.Format("Property '{0}' of type '{1}' cannot be stored in solr field type '{2}'.", propertyName, propertyType.FullName, solrFieldType.Name));
        }
Esempio n. 4
0
        /// <summary>
        /// Parses the specified Solr schema xml.
        /// </summary>
        /// <param name="solrSchemaXml">The Solr schema xml to parse.</param>
        /// <returns>A strongly styped representation of the Solr schema xml.</returns>
        public SolrSchema Parse(XDocument solrSchemaXml)
        {
            var result = new SolrSchema();

            var schemaElem = solrSchemaXml.Element("schema");

            foreach (var fieldNode in schemaElem.XPathSelectElements("types/fieldType|types/fieldtype"))
            {
                var field = new SolrFieldType(fieldNode.Attribute("name").Value, fieldNode.Attribute("class").Value);
                result.SolrFieldTypes.Add(field);
            }

            var fieldsElem = schemaElem.Element("fields");

            foreach (var fieldNode in fieldsElem.Elements("field"))
            {
                var fieldTypeName = fieldNode.Attribute("type").Value;
                var fieldType     = result.FindSolrFieldTypeByName(fieldTypeName);
                if (fieldType == null)
                {
                    throw new SolrNetException(string.Format("Field type '{0}' not found", fieldTypeName));
                }
                var field = new SolrField(fieldNode.Attribute("name").Value, fieldType);
                field.IsRequired = fieldNode.Attribute("required") != null?fieldNode.Attribute("required").Value.ToLower().Equals(Boolean.TrueString.ToLower()) : false;

                field.IsMultiValued = fieldNode.Attribute("multiValued") != null?fieldNode.Attribute("multiValued").Value.ToLower().Equals(Boolean.TrueString.ToLower()) : false;

                field.IsStored = fieldNode.Attribute("stored") != null?fieldNode.Attribute("stored").Value.ToLower().Equals(Boolean.TrueString.ToLower()) : false;

                field.IsIndexed = fieldNode.Attribute("indexed") != null?fieldNode.Attribute("indexed").Value.ToLower().Equals(Boolean.TrueString.ToLower()) : false;

                field.IsDocValues = fieldNode.Attribute("docValues") != null?fieldNode.Attribute("docValues").Value.ToLower().Equals(Boolean.TrueString.ToLower()) : false;

                result.SolrFields.Add(field);
            }

            foreach (var dynamicFieldNode in fieldsElem.Elements("dynamicField"))
            {
                var dynamicField = new SolrDynamicField(dynamicFieldNode.Attribute("name").Value);
                result.SolrDynamicFields.Add(dynamicField);
            }

            foreach (var copyFieldNode in schemaElem.Elements("copyField"))
            {
                var copyField = new SolrCopyField(copyFieldNode.Attribute("source").Value, copyFieldNode.Attribute("dest").Value);
                result.SolrCopyFields.Add(copyField);
            }

            var uniqueKeyNode = schemaElem.Element("uniqueKey");

            if (uniqueKeyNode != null && !string.IsNullOrEmpty(uniqueKeyNode.Value))
            {
                result.UniqueKey = uniqueKeyNode.Value;
            }

            return(result);
        }
 public void DictionaryFields_are_ignored()
 {
     var rule = new MappedPropertiesIsInSolrSchemaRule();
     var mapper = new MappingManager();
     mapper.Add(typeof(SchemaMappingTestDocument).GetProperty("DynamicMapped"), "ma_*");
     var schema = new SolrSchema();
     var fieldType = new SolrFieldType("string", "solr.StrField");
     schema.SolrFields.Add(new SolrField("ma_uaua", fieldType));
     var results = rule.Validate(typeof(SchemaMappingTestDocument), new SolrSchema(), mapper).ToList();
     Assert.AreEqual(0, results.Count);
 }
Esempio n. 6
0
 /// <summary>
 /// Repesents a field in the Solr schema.
 /// </summary>
 /// <param name="name">Field name</param>
 /// <param name="type">Field type</param>
 public SolrField(string name, SolrFieldType type)
 {
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     if (type == null)
     {
         throw new ArgumentNullException("type");
     }
     Name = name;
     Type = type;
 }
Esempio n. 7
0
        /// <summary>
        /// Parses the specified Solr schema xml.
        /// </summary>
        /// <param name="solrSchemaXml">The Solr schema xml to parse.</param>
        /// <returns>A strongly styped representation of the Solr schema xml.</returns>
        public SolrSchema Parse(XDocument solrSchemaXml) {
            var result = new SolrSchema();

            var schemaElem = solrSchemaXml.Element("schema");

            foreach (var fieldNode in schemaElem.XPathSelectElements("types/fieldType|types/fieldtype")) {
                var field = new SolrFieldType(fieldNode.Attribute("name").Value, fieldNode.Attribute("class").Value);
                result.SolrFieldTypes.Add(field);
            }

            var fieldsElem = schemaElem.Element("fields");

            foreach (var fieldNode in fieldsElem.Elements("field")) {
                var fieldTypeName = fieldNode.Attribute("type").Value;
                var fieldType = result.FindSolrFieldTypeByName(fieldTypeName);
                if (fieldType == null)
                    throw new SolrNetException(string.Format("Field type '{0}' not found", fieldTypeName));
                var field = new SolrField(fieldNode.Attribute("name").Value, fieldType);
                field.IsRequired = fieldNode.Attribute("required") != null ? fieldNode.Attribute("required").Value.ToLower().Equals(Boolean.TrueString.ToLower()) : false;
                field.IsMultiValued = fieldNode.Attribute("multiValued") != null ? fieldNode.Attribute("multiValued").Value.ToLower().Equals(Boolean.TrueString.ToLower()) : false;
                field.IsStored = fieldNode.Attribute("stored") != null ? fieldNode.Attribute("stored").Value.ToLower().Equals(Boolean.TrueString.ToLower()) : false;
                field.IsIndexed = fieldNode.Attribute("indexed") != null ? fieldNode.Attribute("indexed").Value.ToLower().Equals(Boolean.TrueString.ToLower()) : false;
                field.IsDocValues = fieldNode.Attribute("docValues") != null ? fieldNode.Attribute("docValues").Value.ToLower().Equals(Boolean.TrueString.ToLower()) : false; 

                result.SolrFields.Add(field);
            }

            foreach (var dynamicFieldNode in fieldsElem.Elements("dynamicField")) {
                var dynamicField = new SolrDynamicField(dynamicFieldNode.Attribute("name").Value);
                result.SolrDynamicFields.Add(dynamicField);
            }

            foreach (var copyFieldNode in schemaElem.Elements("copyField")) {
                var copyField = new SolrCopyField(copyFieldNode.Attribute("source").Value, copyFieldNode.Attribute("dest").Value);
                result.SolrCopyFields.Add(copyField);
            }

            var uniqueKeyNode = schemaElem.Element("uniqueKey");
            if (uniqueKeyNode != null && !string.IsNullOrEmpty(uniqueKeyNode.Value)) {
                result.UniqueKey = uniqueKeyNode.Value;
            }

            return result;
        }
Esempio n. 8
0
        /// <summary>
        /// Parses the specified Solr schema xml.
        /// </summary>
        /// <param name="solrSchemaXml">The Solr schema xml to parse.</param>
        /// <returns>A strongly styped representation of the Solr schema xml.</returns>
        public SolrSchema Parse(XmlDocument solrSchemaXml)
        {
            var result = new SolrSchema();

            foreach (XmlNode fieldNode in solrSchemaXml.SelectNodes("/schema/types/fieldType|/schema/types/fieldtype")) {
                var field = new SolrFieldType(fieldNode.Attributes["name"].Value, fieldNode.Attributes["class"].Value);
                result.SolrFieldTypes.Add(field);
            }

            foreach (XmlNode fieldNode in solrSchemaXml.SelectNodes("/schema/fields/field")) {
                var fieldTypeName = fieldNode.Attributes["type"].Value;
                var fieldType = result.FindSolrFieldTypeByName(fieldTypeName);
                if (fieldType == null)
                    throw new SolrNetException(string.Format("Field type '{0}' not found", fieldTypeName));
                var field = new SolrField(fieldNode.Attributes["name"].Value, fieldType);
                field.IsRequired = fieldNode.Attributes["required"] != null ? fieldNode.Attributes["required"].Value.ToLower().Equals(Boolean.TrueString.ToLower()) : false;
                field.IsMultiValued = fieldNode.Attributes["multiValued"] != null ? fieldNode.Attributes["multiValued"].Value.ToLower().Equals(Boolean.TrueString.ToLower()) : false;
                result.SolrFields.Add(field);
            }

            foreach (XmlNode dynamicFieldNode in solrSchemaXml.SelectNodes("/schema/fields/dynamicField")) {
                var dynamicField = new SolrDynamicField(dynamicFieldNode.Attributes["name"].Value);
                result.SolrDynamicFields.Add(dynamicField);
            }

            foreach (XmlNode copyFieldNode in solrSchemaXml.SelectNodes("/schema/copyField")) {
                var copyField = new SolrCopyField(copyFieldNode.Attributes["source"].Value, copyFieldNode.Attributes["dest"].Value);
                result.SolrCopyFields.Add(copyField);
            }

            var uniqueKeyNode = solrSchemaXml.SelectSingleNode("/schema/uniqueKey");
            if (uniqueKeyNode != null && !string.IsNullOrEmpty(uniqueKeyNode.InnerText)) {
                result.UniqueKey = uniqueKeyNode.InnerText;
            }

            return result;
        }