private void ProcessFullTextIndexes(TypeDef typeDef) { if (ShouldSkipFulltextIndex(typeDef)) { return; } var fullTextIndexDef = new FullTextIndexDef(typeDef); foreach (var fieldDef in typeDef.Fields.Where(f => f.UnderlyingProperty != null)) { var fullTextAttribute = fieldDef.UnderlyingProperty .GetAttribute <FullTextAttribute>(AttributeSearchOptions.InheritAll); if (fullTextAttribute == null) { continue; } var fullTextField = new FullTextFieldDef(fieldDef.Name, fullTextAttribute.Analyzed) { Configuration = fullTextAttribute.Configuration, TypeFieldName = fullTextAttribute.DataTypeField }; fullTextIndexDef.Fields.Add(fullTextField); } if (fullTextIndexDef.Fields.Count > 0) { context.ModelDef.FullTextIndexes.Add(fullTextIndexDef); } }
public void OnDefinitionsBuilt(Building.BuildingContext context, DomainModelDef model) { var documentDef = model.Types[typeof(noFTModel.Document)]; var title = documentDef.Fields["Title"]; var documentBody = documentDef.Fields["DocumentBody"]; var titleIndex = documentDef.Fields.IndexOf(title); var documentBodyIndex = documentDef.Fields.IndexOf(documentBody); var oldFieldsMap = documentDef.Fields.ToArray(); documentDef.Fields.Clear(); oldFieldsMap[titleIndex] = documentBody; oldFieldsMap[documentBodyIndex] = title; foreach (var fieldDef in oldFieldsMap) { documentDef.Fields.Add(fieldDef); } var ftIndexDef = new FullTextIndexDef(documentDef); ftIndexDef.Fields.Add( new FullTextFieldDef("DocumentBody", false) { Configuration = "English", TypeFieldName = "Extension" }); ftIndexDef.Fields.Add(new FullTextFieldDef("Title", false) { Configuration = "English" }); model.FullTextIndexes.Add(ftIndexDef); }
private void DefineFullTextIndex(DomainModelDef model) { var customerType = model.Types[typeof(Customer)]; var fieldsToDefineIndex = customerType.Fields .Where(f => f.Name.In("FirstName", "LastName")) .Select(f => new FullTextFieldDef(f.Name, true) { Configuration = "English" }); var index = new FullTextIndexDef(customerType); index.Fields.AddRange(fieldsToDefineIndex); model.FullTextIndexes.Add(index); var addressType = model.Types[typeof(Address)]; fieldsToDefineIndex = addressType.Fields .Where(f => f.Name.In("Country", "Region", "City", "Street")) .Select(f => new FullTextFieldDef(f.Name, true) { Configuration = "English" }); index = new FullTextIndexDef(addressType); index.Fields.AddRange(fieldsToDefineIndex); model.FullTextIndexes.Add(index); }
public void OnDefinitionsBuilt(Building.BuildingContext context, Building.Definitions.DomainModelDef model) { var documentDef = model.Types[typeof(noFTModel.Document)]; var ftIndexDef = new FullTextIndexDef(documentDef); ftIndexDef.Fields.Add(new FullTextFieldDef("Title", false) { Configuration = "English" }); model.FullTextIndexes.Add(ftIndexDef); }
public void OnDefinitionsBuilt(Building.BuildingContext context, DomainModelDef model) { var documentDef = model.Types[typeof(noFTModel.Document)]; var realExtensionField = documentDef.DefineField("RealExtension", typeof(string)); realExtensionField.Length = 50; var ftIndexDef = new FullTextIndexDef(documentDef); ftIndexDef.Fields.Add( new FullTextFieldDef("DocumentBody", false) { Configuration = "English", TypeFieldName = "RealExtension" }); model.FullTextIndexes.Add(ftIndexDef); }
private FieldInfo BuildDeclaredField(TypeInfo type, FieldDef fieldDef) { BuildLog.Info(Strings.LogBuildingDeclaredFieldXY, type.Name, fieldDef.Name); var fieldInfo = new FieldInfo(type, fieldDef.Attributes) { UnderlyingProperty = fieldDef.UnderlyingProperty, Name = fieldDef.Name, OriginalName = fieldDef.Name, MappingName = fieldDef.MappingName, ValueType = fieldDef.ValueType, ItemType = fieldDef.ItemType, Length = fieldDef.Length, Scale = fieldDef.Scale, Precision = fieldDef.Precision, Validators = fieldDef.Validators, }; if (fieldInfo.IsStructure && DeclaresOnValidate(fieldInfo.ValueType)) { fieldInfo.Validators.Add(new StructureFieldValidator()); } if (fieldInfo.IsEntitySet && DeclaresOnValidate(fieldInfo.ValueType)) { fieldInfo.Validators.Add(new EntitySetFieldValidator()); } type.Fields.Add(fieldInfo); if (fieldInfo.IsEntitySet) { AssociationBuilder.BuildAssociation(context, fieldDef, fieldInfo); return(fieldInfo); } if (fieldInfo.IsEntity) { var fields = context.Model.Types[fieldInfo.ValueType].Fields.Where(f => f.IsPrimaryKey); // Adjusting default value if any if (fields.Count() == 1 && fieldDef.DefaultValue != null) { fieldInfo.DefaultValue = ValueTypeBuilder.AdjustValue(fieldInfo, fields.First().ValueType, fieldDef.DefaultValue); } BuildNestedFields(null, fieldInfo, fields); if (!IsAuxiliaryType(type)) { AssociationBuilder.BuildAssociation(context, fieldDef, fieldInfo); if (type.IsStructure) { fieldInfo.Associations.ForEach(a => context.DiscardedAssociations.Add(a)); } } // Adjusting type discriminator field for references if (fieldDef.IsTypeDiscriminator) { type.Hierarchy.TypeDiscriminatorMap.Field = fieldInfo.Fields.First(); } } if (fieldInfo.IsStructure) { BuildNestedFields(null, fieldInfo, context.Model.Types[fieldInfo.ValueType].Fields); var structureFullTextIndex = context.ModelDef.FullTextIndexes.TryGetValue(fieldInfo.ValueType); if (structureFullTextIndex != null) { var hierarchyTypeInfo = context.Model.Types[fieldInfo.DeclaringType.UnderlyingType]; var structureTypeInfo = context.Model.Types[fieldInfo.ValueType]; var currentIndex = context.ModelDef.FullTextIndexes.TryGetValue(hierarchyTypeInfo.UnderlyingType); if (currentIndex == null) { currentIndex = new FullTextIndexDef(context.ModelDef.Types.TryGetValue(type.UnderlyingType)); context.ModelDef.FullTextIndexes.Add(currentIndex); } currentIndex.Fields.AddRange(structureFullTextIndex.Fields .Select(f => new { fieldInfo.DeclaringType .StructureFieldMapping[new Pair <FieldInfo>(fieldInfo, structureTypeInfo.Fields[f.Name])].Name, f.IsAnalyzed, f.Configuration, f.TypeFieldName }) .Select(g => new FullTextFieldDef(g.Name, g.IsAnalyzed) { Configuration = g.Configuration, TypeFieldName = g.TypeFieldName })); } } if (fieldInfo.IsPrimitive) { fieldInfo.DefaultValue = fieldDef.DefaultValue; fieldInfo.DefaultSqlExpression = fieldDef.DefaultSqlExpression; fieldInfo.Column = BuildDeclaredColumn(fieldInfo); if (fieldDef.IsTypeDiscriminator) { type.Hierarchy.TypeDiscriminatorMap.Field = fieldInfo; } } return(fieldInfo); }