Exemplo n.º 1
0
        /// <summary>
        /// Update search Result Type with specified data
        /// </summary>
        /// <param name="resultTypeId">Existing Result Type Id</param>
        /// <param name="type">Data transfer object used for updating</param>
        /// <returns></returns>
        public ResultItemType UpdateResultType(int resultTypeId, ResultTypeDTO type)
        {
            var resultTypesManager = new ResultItemTypeManager(_searchProxy);
            var resultType         = resultTypesManager.GetResultItemTypeByID(resultTypeId, _searchOwner);

            resultType.Name = type.Name;
            resultType.DisplayTemplateUrl = type.DisplayTemplateUrl;
            resultType.RulePriority       = type.Priority;

            if (!string.IsNullOrEmpty(type.ResultSource))
            {
                var source = GetResultsSource(type.ResultSource);
                resultType.SourceID = source.Id;
            }

            var rules = new PropertyRuleCollection();

            foreach (var builtInRule in type.BuiltInRules)
            {
                rules.Add(GetBuiltInPropertyRule(builtInRule));
            }
            foreach (var rule in type.CustomRules)
            {
                rules.Add(CreatePropertyRule(rule.ManagedPropertyName, rule.Operator, rule.Values));
            }
            resultType.Rules = rules;

            return(resultTypesManager.UpdateResultItemType(resultType));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Ensure search Result Type
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public ResultItemType EnsureResultType(ResultTypeDTO type)
        {
            var resultTypesManager = new ResultItemTypeManager(_searchProxy);
            var resultType         = resultTypesManager.GetResultItemTypes(_searchOwner, true).FirstOrDefault(rt => rt.Name.Equals(type.Name, StringComparison.OrdinalIgnoreCase));

            if (resultType != null)
            {
                return(UpdateResultType(resultType.ID, type));
            }

            resultType = new ResultItemType(_searchOwner)
            {
                Name = type.Name,
                DisplayTemplateUrl = type.DisplayTemplateUrl,
                RulePriority       = type.Priority
            };

            if (!string.IsNullOrEmpty(type.ResultSource))
            {
                var source = GetResultsSource(type.ResultSource);
                resultType.SourceID = source.Id;
            }

            var rules = new PropertyRuleCollection();

            foreach (var builtInRule in type.BuiltInRules)
            {
                rules.Add(GetBuiltInPropertyRule(builtInRule));
            }
            foreach (var rule in type.CustomRules)
            {
                rules.Add(CreatePropertyRule(rule.ManagedPropertyName, rule.Operator, rule.Values));
            }
            resultType.Rules = rules;

            return(resultTypesManager.AddResultItemType(resultType));
        }