public virtual EmbeddedMapping GetMapping() { EmbeddedMapping mapping = new EmbeddedMapping(_member); mapping.Prefix = _prefix; return mapping; }
private void BuildProperty( DocumentMapping documentMapping, MemberInfo member, Analyzer parentAnalyzer, bool isRoot, string path, BuildContext context ) { IFieldBridge bridge = null; var analyzer = GetAnalyzer(member) ?? parentAnalyzer; var boost = GetBoost(member); var getter = GetGetterFast(documentMapping.MappedClass, member); var documentIdAttribute = AttributeUtil.GetAttribute<DocumentIdAttribute>(member); if (documentIdAttribute != null) { string documentIdName = documentIdAttribute.Name ?? member.Name; bridge = GetFieldBridge(member); if (isRoot) { if (!(bridge is ITwoWayFieldBridge)) { throw new SearchException("Bridge for document id does not implement TwoWayFieldBridge: " + member.Name); } documentMapping.DocumentId = new DocumentIdMapping( documentIdName, member.Name, (ITwoWayFieldBridge)bridge, getter ) { Boost = boost }; } else { // Components should index their document id documentMapping.Fields.Add(new FieldMapping( GetAttributeName(member, documentIdName), bridge, getter ) { Store = Attributes.Store.Yes, Index = Attributes.Index.UnTokenized, Boost = boost }); } } var fieldAttributes = AttributeUtil.GetFields(member); if (fieldAttributes.Length > 0) { if (bridge == null) bridge = GetFieldBridge(member); foreach (var fieldAttribute in fieldAttributes) { var fieldAnalyzer = GetAnalyzerByType(fieldAttribute.Analyzer) ?? analyzer; var field = new FieldMapping( GetAttributeName(member, fieldAttribute.Name), bridge, getter ) { Store = fieldAttribute.Store, Index = fieldAttribute.Index, Analyzer = fieldAnalyzer }; documentMapping.Fields.Add(field); } } var embeddedAttribute = AttributeUtil.GetAttribute<IndexedEmbeddedAttribute>(member); if (embeddedAttribute != null) { int oldMaxLevel = maxLevel; int potentialLevel = embeddedAttribute.Depth + level; if (potentialLevel < 0) { potentialLevel = int.MaxValue; } maxLevel = potentialLevel > maxLevel ? maxLevel : potentialLevel; level++; System.Type elementType = embeddedAttribute.TargetElement ?? GetMemberTypeOrGenericArguments(member); var localPrefix = embeddedAttribute.Prefix == "." ? member.Name + "." : embeddedAttribute.Prefix; if (maxLevel == int.MaxValue && context.Processed.Contains(elementType)) { throw new SearchException( string.Format( "Circular reference, Duplicate use of {0} in root entity {1}#{2}", elementType.FullName, context.Root.MappedClass.FullName, path + localPrefix)); } if (level <= maxLevel) { context.Processed.Add(elementType); // push var embedded = new EmbeddedMapping(new DocumentMapping(elementType) { Boost = GetBoost(member), Analyzer = GetAnalyzer(member) ?? parentAnalyzer }, getter) { Prefix = localPrefix }; BuildClass(embedded.Class, false, path + localPrefix, context); /** * We will only index the "expected" type but that's OK, HQL cannot do downcasting either */ // ayende: because we have to deal with generic collections here, we aren't // actually using the element type to determine what the value is, since that // was resolved to the element type of the possible collection Type actualFieldType = GetMemberTypeOrGenericCollectionType(member); embedded.IsCollection = typeof(IEnumerable).IsAssignableFrom(actualFieldType); documentMapping.Embedded.Add(embedded); context.Processed.Remove(actualFieldType); // pop } else if (logger.IsDebugEnabled) { logger.Debug("Depth reached, ignoring " + path + localPrefix); } level--; maxLevel = oldMaxLevel; // set back the old max level } if (AttributeUtil.HasAttribute<ContainedInAttribute>(member)) { documentMapping.ContainedIn.Add(new ContainedInMapping(getter)); } }