예제 #1
0
        private Dictionary <string, List <string> > MapDocumentFieldsToTypeIndexer(Type type, IEnumerable <string> documentFieldNames)
        {
            Dictionary <string, List <string> > dictionary = documentFieldNames.ToDictionary <string, string, List <string> >((Func <string, string>)(f => f.ToLowerInvariant()), (Func <string, List <string> >)(f => this.GetTypeFieldNames(f).ToList <string>()));

            foreach (PropertyInfo property in this.GetProperties(type))
            {
                string index        = property.Name;
                Type   propertyType = property.PropertyType;
                IIndexFieldNameFormatterAttribute formatterAttribute = this.GetIndexFieldNameFormatterAttribute((MemberInfo)property);
                string fieldName = property.Name;
                if (formatterAttribute != null)
                {
                    index     = formatterAttribute.GetIndexFieldName(index);
                    fieldName = formatterAttribute.GetTypeFieldName(fieldName);
                }
                if (!this.schema.AllFieldNames.Contains(index))
                {
                    SolrSearchFieldConfiguration fieldConfiguration = this.fieldMap.GetFieldConfiguration(propertyType) as SolrSearchFieldConfiguration;
                    if (fieldConfiguration != null)
                    {
                        index = fieldConfiguration.FormatFieldName(index, (ISearchIndexSchema)this.schema, this.currentCultureCode, (string)null);
                    }
                }
                if (dictionary.ContainsKey(index))
                {
                    dictionary[index].Add(fieldName);
                }
            }
            return(dictionary);
        }
예제 #2
0
        private string ProcessFieldName(string fieldName, string fieldTypeKey, Type returnType, CultureInfo culture, string returnTypeString = "", bool aggressiveResolver = false)
        {
            string strippedFieldName = this.StripKnownExtensions(fieldName);

            strippedFieldName = strippedFieldName.Replace(" ", "_").ToLowerInvariant();
            string cultureCode = string.Empty;

            cultureCode = culture?.TwoLetterISOLanguageName ?? this.currentCultureCode;
            this.Debug(string.Format("Processing Field Name : {0} with parameters: \n\tStripped Field Name: {1} \n\tResolved culture code : {2}", (object)fieldName, (object)strippedFieldName, (object)cultureCode));
            SolrSearchFieldConfiguration fieldConfiguration1 = this.fieldMap.GetFieldConfiguration(strippedFieldName) as SolrSearchFieldConfiguration;

            if (fieldConfiguration1 != null)
            {
                string resolvedFieldName = fieldConfiguration1.FormatFieldName(strippedFieldName, (ISearchIndexSchema)this.schema, cultureCode, (string)null);
                this.LogResolutionResult(fieldName, resolvedFieldName, "Field Name Map");
                return(resolvedFieldName);
            }
            if (this.schema.AllFieldNames.Contains(strippedFieldName))
            {
                this.LogResolutionResult(fieldName, strippedFieldName, "solr schema Fields");
                return(strippedFieldName);
            }
            if (!string.IsNullOrEmpty(returnTypeString))
            {
                SolrSearchFieldConfiguration configurationByReturnType = this.fieldMap.GetFieldConfigurationByReturnType(returnTypeString) as SolrSearchFieldConfiguration;
                string reason = string.Format("return Type String: {0}", (object)returnTypeString);
                if (configurationByReturnType != null)
                {
                    string resolvedFieldName = configurationByReturnType.FormatFieldName(strippedFieldName, (ISearchIndexSchema)this.schema, cultureCode, (string)null);
                    this.LogResolutionResult(fieldName, resolvedFieldName, reason);
                    return(resolvedFieldName);
                }
            }
            if (returnType != (Type)null)
            {
                SolrSearchFieldConfiguration fieldConfiguration2 = (SolrSearchFieldConfiguration)this.fieldMap.GetFieldConfiguration(returnType, (Func <List <SolrSearchFieldConfiguration>, AbstractSearchFieldConfiguration>)(list => this.ResolveMultipleFieldConfiguration(list, fieldName, strippedFieldName, returnType, cultureCode, returnTypeString, fieldTypeKey)));
                string reason = fieldConfiguration2 == null ? string.Empty : string.Format("return Type : {0}", (object)fieldConfiguration2.SystemType.FullName);
                if (fieldConfiguration2 != null)
                {
                    string resolvedFieldName = fieldConfiguration2.FormatFieldName(strippedFieldName, (ISearchIndexSchema)this.schema, cultureCode, (string)null);
                    this.LogResolutionResult(fieldName, resolvedFieldName, reason);
                    return(resolvedFieldName);
                }
            }
            if (aggressiveResolver)
            {
                string resolvedFieldName = this.AggressiveProcessFieldName(fieldName.ToLower(), returnType, cultureCode, returnTypeString, fieldTypeKey, fieldName.ToLowerInvariant());
                this.LogResolutionResult(fieldName, resolvedFieldName, "Template Field");
                return(resolvedFieldName);
            }
            this.Debug(string.Format("Processing Field Name : {0}. No match found", (object)fieldName.ToLowerInvariant()));
            return(fieldName.ToLowerInvariant());
        }
예제 #3
0
        public IEnumerable <SearchIndexTerm> GetTermsByFieldName(string fieldName, string filter)
        {
            SolrSearchFieldConfiguration fieldConfiguration = index.Configuration.FieldMap.GetFieldConfiguration(fieldName.ToLowerInvariant()) as SolrSearchFieldConfiguration;

            if (fieldConfiguration != null)
            {
                fieldName = fieldConfiguration.FormatFieldName(fieldName, Index.Schema, null, settings.DefaultLanguage());
            }
            IEnumerable <SearchIndexTerm> searchIndexTerms = new HashSet <SearchIndexTerm>();

            return(searchIndexTerms);
        }
예제 #4
0
        private List <SolrSearchFieldConfiguration> AggressiveResolveFieldConfigurations(string fieldName, Type returnType, string cultureCode, string returnTypeString = "", string fieldTypeKey = "")
        {
            List <TemplateResolver> list = this.FindTemplateField(fieldName).ToList <TemplateResolver>();
            Action <List <SolrSearchFieldConfiguration> > action = (Action <List <SolrSearchFieldConfiguration> >)(configurations =>
            {
                if (!(returnType != (Type)null))
                {
                    return;
                }
                this.fieldMap.AddFieldByFieldName(fieldName, returnType, configurations);
            });

            if (list.Any <TemplateResolver>())
            {
                StringBuilder stringBuilder = new StringBuilder();
                foreach (TemplateResolver templateResolver in list)
                {
                    stringBuilder.AppendFormat("\t type: {0}\n", (object)templateResolver.Type);
                }
                if (list.Count > 1)
                {
                    this.Debug(string.Format("Processing Field Name : {0} Search field name in Solr with Template Resolver is returning multiple entry: \n{1}'", (object)fieldName, (object)stringBuilder));
                }
                else
                {
                    this.Debug(string.Format("Processing Field Name : {0} Search field name in Solr with Template Resolver is returning entry: \n{1}'", (object)fieldName, (object)stringBuilder));
                }
                List <SolrSearchFieldConfiguration> fieldConfigurationList = new List <SolrSearchFieldConfiguration>();
                foreach (TemplateResolver templateResolver in list)
                {
                    if (templateResolver.Type != null)
                    {
                        SolrSearchFieldConfiguration configurationByFieldTypeName = (SolrSearchFieldConfiguration)this.fieldMap.GetFieldConfigurationByFieldTypeName(templateResolver.Type);
                        if (configurationByFieldTypeName == null)
                        {
                            this.Debug(string.Format("Processing Field Name : {0} Search field name in Solr with Template Resolver. Entry {1} is being skipped. Reason: No Field Type Name '{2}' found in field types section of solr configuration.", (object)fieldName, (object)templateResolver.Type, (object)templateResolver.Type));
                        }
                        else
                        {
                            SolrSearchFieldConfiguration fieldConfiguration = (SolrSearchFieldConfiguration)configurationByFieldTypeName.Clone();
                            fieldConfiguration.FieldTypeName = fieldConfiguration.FieldTypeName ?? templateResolver.Type;
                            fieldConfigurationList.Add(fieldConfiguration);
                        }
                    }
                }
                action(fieldConfigurationList);
                return(fieldConfigurationList);
            }
            this.Debug(string.Format("Processing Field Name : {0} Search field name in Solr with Template Resolver is returning no entry.", (object)fieldName));
            action((List <SolrSearchFieldConfiguration>) new SolrFieldMap.NullReturnType());
            return(new List <SolrSearchFieldConfiguration>());
        }
예제 #5
0
 protected virtual string GetSearchFieldConfiguration(string fieldName, string cultureCode, SolrSearchFieldConfiguration configurationByType)
 {
     return(configurationByType.FormatFieldName(fieldName, (ISearchIndexSchema)this.schema, cultureCode, this.settings.DefaultLanguage()));
 }
예제 #6
0
        protected virtual AbstractSearchFieldConfiguration ResolveMultipleFieldConfiguration(List <SolrSearchFieldConfiguration> list, string fieldName, string strippedFieldName, Type returnType, string cultureCode, string returnTypeString, string fieldTypeKey)
        {
            string str = list.Where <SolrSearchFieldConfiguration>((Func <SolrSearchFieldConfiguration, bool>)(l => l != null)).Select <SolrSearchFieldConfiguration, string>((Func <SolrSearchFieldConfiguration, string>)(l => l.FieldNameFormat)).Aggregate <string>((Func <string, string, string>)((current, next) => string.Format("\t\t{0},\n\t\t{1}", (object)current, (object)next)));

            this.Debug(string.Format("Processing Field Name : {0}. Resolving Multiple Field found on Solr Field Map. \n\treturn type '{1}'. \n\tFieldNameFormat: \n{2}", (object)fieldName, (object)returnType.FullName, (object)str));
            List <SolrSearchFieldConfiguration> source = this.fieldMap.GetFieldConfigurations(strippedFieldName, returnType);

            if (!source.Any <SolrSearchFieldConfiguration>() && source.GetType() != typeof(SolrFieldMap.NullReturnType))
            {
                source = this.AggressiveResolveFieldConfigurations(strippedFieldName, returnType, cultureCode, returnTypeString, fieldTypeKey);
            }
            else
            {
                this.Debug(string.Format("Processing Field Name : {0}. Resolving Multiple Field found on Solr Field Map. Cache Found. Get template resolver result from cache.", (object)fieldName));
            }
            List <SolrSearchFieldConfiguration> list1 = source.Where <SolrSearchFieldConfiguration>((Func <SolrSearchFieldConfiguration, bool>)(c =>
            {
                if (string.IsNullOrEmpty(fieldTypeKey))
                {
                    return(true);
                }
                if (c.FieldTypeName != null)
                {
                    return(fieldTypeKey.ToLower() == c.FieldTypeName.ToLower());
                }
                return(false);
            })).ToList <SolrSearchFieldConfiguration>();

            if (!list1.Any <SolrSearchFieldConfiguration>())
            {
                this.Debug(string.Format("Processing Field Name : {0}. Resolving Multiple Field found on Solr Field Map. No matching template field on index field name '{1}', return type '{2}' and field type '{3}'", new object[4]
                {
                    (object)fieldName,
                    (object)strippedFieldName,
                    (object)returnType.Name,
                    (object)fieldTypeKey
                }));
                return((AbstractSearchFieldConfiguration)list.First <SolrSearchFieldConfiguration>());
            }
            foreach (SolrSearchFieldConfiguration fieldConfiguration in list)
            {
                SolrSearchFieldConfiguration item = fieldConfiguration;
                if (list1.Any <SolrSearchFieldConfiguration>((Func <SolrSearchFieldConfiguration, bool>)(c =>
                {
                    if (c != null)
                    {
                        return(c.FieldNameFormat == item.FieldNameFormat);
                    }
                    return(false);
                })))
                {
                    return((AbstractSearchFieldConfiguration)item);
                }
            }
            this.Debug(string.Format("Processing Field Name : {0}. Resolving Multiple Field found on Solr Field Map. No matching solr search field configuration on index field name '{1}', return type '{2}' and field type '{3}'. ", new object[4]
            {
                (object)fieldName,
                (object)strippedFieldName,
                (object)returnType.Name,
                (object)fieldTypeKey
            }) + string.Format("Returning the first configuration with Field Name format: {0}", (object)list.First <SolrSearchFieldConfiguration>().FieldNameFormat));
            return((AbstractSearchFieldConfiguration)list.First <SolrSearchFieldConfiguration>());
        }