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)); }
/// <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)); }
/// <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); }
/// <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; }
/// <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; }