Пример #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
 protected virtual string GetSearchFieldConfiguration(string fieldName, string cultureCode, SolrSearchFieldConfiguration configurationByType)
 {
     return(configurationByType.FormatFieldName(fieldName, (ISearchIndexSchema)this.schema, cultureCode, this.settings.DefaultLanguage()));
 }