public override string GetIndexFieldName(string fieldName)
 {
     if (_schema != null && _schema.FindSolrFieldByName(fieldName) != null || _schema.SolrDynamicFields.Any(x => fieldName.EndsWith(x.Name.Substring(1))))
     {
         return(fieldName);
     }
     //at this point we can't be sure what type the data is in the field, our best bet would be a text field.
     return(AppendSolrText(fieldName));
 }
Esempio n. 2
0
        /// <summary>
        /// Validates the specified the mapped document against the solr schema.
        /// </summary>
        /// <param name="documentType">Document type</param>
        /// <param name="solrSchema">The solr schema.</param>
        /// <param name="mappingManager">The mapping manager.</param>
        /// <returns>
        /// A collection of <see cref="ValidationResult"/> objects with any issues found during validation.
        /// </returns>
        public IEnumerable <ValidationResult> Validate(Type documentType, SolrSchema solrSchema, IReadOnlyMappingManager mappingManager)
        {
            var collectionFieldParser = new CollectionFieldParser(null); // Used to check if the type is a collection type.

            foreach (var prop in mappingManager.GetFields(documentType))
            {
                var solrField = solrSchema.FindSolrFieldByName(prop.Key);
                if (solrField == null)
                {
                    continue;
                }
                var isCollection = collectionFieldParser.CanHandleType(prop.Value.Property.PropertyType);
                if (solrField.IsMultiValued && !isCollection)
                {
                    yield return(new ValidationError(String.Format("SolrField '{0}' is multivalued while property '{1}.{2}' is not mapped as a collection.", solrField.Name, prop.Value.Property.DeclaringType, prop.Value.Property.Name)));
                }
                else if (!solrField.IsMultiValued && isCollection)
                {
                    yield return(new ValidationError(String.Format("SolrField '{0}' is not multivalued while property '{1}.{2}' is mapped as a collection.", solrField.Name, prop.Value.Property.DeclaringType, prop.Value.Property.Name)));
                }
            }
        }
Esempio n. 3
0
 public IEnumerable <ValidationResult> Validate(Type documentType, SolrSchema solrSchema, IReadOnlyMappingManager mappingManager)
 {
     foreach (var x in mappingManager.GetFields(documentType))
     {
         var solrField = solrSchema.FindSolrFieldByName(x.Key);
         if (solrField == null)
         {
             continue;
         }
         foreach (var checker in fieldTypeCheckers)
         {
             if (!checker.CanHandleType(x.Value.Property.PropertyType))
             {
                 continue;
             }
             var i = checker.Validate(solrField.Type, x.Value.Property.Name, x.Value.Property.PropertyType);
             if (i != null)
             {
                 yield return(i);
             }
         }
     }
 }