Exemplo n.º 1
0
        /// <summary>
        /// Ensure a search result source
        /// </summary>
        /// <param name="ssa">The search service application.</param>
        /// <param name="resultSourceName">The result source name</param>
        /// <param name="level">The search object level.</param>
        /// <param name="searchProvider">The search provider for the result source.</param>
        /// <param name="contextWeb">The SPWeb to retrieve the search context.</param>
        /// <param name="query">The search query in KQL format.</param>
        /// <param name="properties">Query properties.</param>
        /// <param name="overwrite">if set to <c>true</c> [overwrite].</param>
        /// <param name="isDefaultResultSourceForOwner">Whether this result source will be flagged as the default for the current search owner</param>
        /// <returns>
        /// The result source.
        /// </returns>
        private static Source InnerEnsureResultSource(SearchServiceApplication ssa, string resultSourceName, SearchObjectLevel level, string searchProvider, SPWeb contextWeb, string query, QueryTransformProperties properties, bool overwrite, bool isDefaultResultSourceForOwner)
        {
            var federationManager = new FederationManager(ssa);
            var searchOwner       = new SearchObjectOwner(level, contextWeb);

            var resultSource = federationManager.GetSourceByName(resultSourceName, searchOwner);

            if (resultSource != null && overwrite)
            {
                federationManager.RemoveSource(resultSource);
            }

            if (resultSource == null || overwrite)
            {
                resultSource            = federationManager.CreateSource(searchOwner);
                resultSource.Name       = resultSourceName;
                resultSource.ProviderId = federationManager.ListProviders()[searchProvider].Id;
                resultSource.CreateQueryTransform(properties, query);
                resultSource.Commit();

                if (isDefaultResultSourceForOwner)
                {
                    federationManager.UpdateDefaultSource(resultSource.Id, searchOwner);
                }
            }

            return(resultSource);
        }
Exemplo n.º 2
0
        private void DeploySearchResult(object modelHost, Microsoft.SharePoint.SPSite site, SearchResultDefinition definition)
        {
            FederationManager federationManager = null;
            SearchObjectOwner searchOwner       = null;

            var currentSource = GetCurrentSource(site, definition, out federationManager, out searchOwner);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioning,
                Object           = currentSource,
                ObjectType       = typeof(Source),
                ObjectDefinition = definition,
                ModelHost        = modelHost
            });

            if (currentSource == null)
            {
                currentSource      = federationManager.CreateSource(searchOwner);
                currentSource.Name = definition.Name;

                if (definition.ProviderId.HasValue)
                {
                    currentSource.ProviderId = definition.ProviderId.Value;
                }
                else
                {
                    currentSource.ProviderId = GetProviderByName(federationManager, definition.ProviderName).Id;
                }
            }

            currentSource.Description = definition.Description ?? string.Empty;
            currentSource.CreateQueryTransform(new QueryTransformProperties(), definition.Query);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioned,
                Object           = currentSource,
                ObjectType       = typeof(Source),
                ObjectDefinition = definition,
                ModelHost        = modelHost
            });

            currentSource.Commit();

            if (definition.IsDefault)
            {
                federationManager.UpdateDefaultSource(currentSource.Id, searchOwner);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Ensure a search result source
        /// </summary>
        /// <param name="ssa">The search service application.</param>
        /// <param name="resultSourceName">The result source name</param>
        /// <param name="level">The search object level.</param>
        /// <param name="searchProvider">The search provider for the result source.</param>
        /// <param name="contextWeb">The SPWeb to retrieve the search context.</param>
        /// <param name="query">The search query in KQL format.</param>
        /// <param name="properties">Query properties.</param>
        /// <param name="overwrite">if set to <c>true</c> [overwrite].</param>
        /// <param name="isDefaultResultSourceForOwner">Whether this result source will be flagged as the default for the current search owner</param>
        /// <returns>
        /// The result source.
        /// </returns>
        private static Source InnerEnsureResultSource(SearchServiceApplication ssa, string resultSourceName, SearchObjectLevel level, string searchProvider, SPWeb contextWeb, string query, QueryTransformProperties properties, bool overwrite, bool isDefaultResultSourceForOwner)
        {
            var federationManager = new FederationManager(ssa);
            var searchOwner = new SearchObjectOwner(level, contextWeb);

            var resultSource = federationManager.GetSourceByName(resultSourceName, searchOwner);

            if (resultSource != null && overwrite)
            {
                federationManager.RemoveSource(resultSource);
            }

            if (resultSource == null || overwrite)
            {
                resultSource = federationManager.CreateSource(searchOwner);
                resultSource.Name = resultSourceName;
                resultSource.ProviderId = federationManager.ListProviders()[searchProvider].Id;
                resultSource.CreateQueryTransform(properties, query);
                resultSource.Commit();

                if (isDefaultResultSourceForOwner)
                {
                    federationManager.UpdateDefaultSource(resultSource.Id, searchOwner);
                }
            }

            return resultSource;
        }