예제 #1
0
        private FilterDef CreateFilterDefinition(FullTextFilterDefAttribute att)
        {
            try
            {
                Activator.CreateInstance(att.Impl);
            }
            catch (Exception ex)
            {
                throw new SearchException("Unable to create Filter class: " + att.Impl.FullName, ex);
            }

            var filterDefinition = new FilterDef
            {
                Name  = att.Name,
                Cache = att.Cache,
                Impl  = att.Impl
            };

            foreach (var method in filterDefinition.Impl.GetMethods())
            {
                if (AttributeUtil.HasAttribute <FactoryAttribute>(method))
                {
                    if (filterDefinition.FactoryMethod != null)
                    {
                        throw new SearchException("Multiple Factory methods found " + filterDefinition.Name + ":" +
                                                  filterDefinition.Impl.FullName + "." + method.Name);
                    }
                    filterDefinition.FactoryMethod = method;
                }

                if (AttributeUtil.HasAttribute <KeyAttribute>(method))
                {
                    if (filterDefinition.KeyMethod != null)
                    {
                        throw new SearchException("Multiple Key methods found " + filterDefinition.Name + ":" +
                                                  filterDefinition.Impl.FullName + "." + method.Name);
                    }
                    filterDefinition.KeyMethod = method;
                }
            }

            foreach (var prop in filterDefinition.Impl.GetProperties())
            {
                if (AttributeUtil.HasAttribute <FilterParameterAttribute>(prop))
                {
                    filterDefinition.Setters[prop.Name] = prop;
                }
            }

            return(filterDefinition);
        }
예제 #2
0
        private FilterDef BuildFilterDef(FullTextFilterDefAttribute attribute)
        {
            var filterDef = new FilterDef
            {
                Name  = attribute.Name,
                Impl  = attribute.Impl,
                Cache = attribute.Cache
            };

            try {
                Activator.CreateInstance(filterDef.Impl);
            }
            catch (Exception e) {
                throw new SearchException("Unable to create Filter class: " + filterDef.Impl.FullName, e);
            }

            foreach (var method in filterDef.Impl.GetMethods())
            {
                if (AttributeUtil.HasAttribute <FactoryAttribute>(method))
                {
                    if (filterDef.FactoryMethod != null)
                    {
                        throw new SearchException("Multiple Factory methods found " + filterDef.Name + ":" +
                                                  filterDef.Impl.FullName + "." + method.Name);
                    }
                    filterDef.FactoryMethod = method;
                }

                if (AttributeUtil.HasAttribute <KeyAttribute>(method))
                {
                    if (filterDef.KeyMethod != null)
                    {
                        throw new SearchException("Multiple Key methods found " + filterDef.Name + ":" +
                                                  filterDef.Impl.FullName + "." + method.Name);
                    }
                    filterDef.KeyMethod = method;
                }
            }

            // Use properties rather than the Java setter logic idea
            foreach (PropertyInfo prop in filterDef.Impl.GetProperties())
            {
                if (AttributeUtil.HasAttribute <FilterParameterAttribute>(prop))
                {
                    filterDef.AddSetter(prop);
                }
            }

            return(filterDef);
        }
예제 #3
0
 public bool HasContainedInDefinition(MemberInfo member)
 {
     return(AttributeUtil.HasAttribute <ContainedInAttribute>(member));
 }
예제 #4
0
        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));
            }
        }
 private bool IsIndexed(Type type)
 {
     return(AttributeUtil.HasAttribute <IndexedAttribute>(type));
 }