/// <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); }
/// <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; }
protected SearchProvider GetProviderByName(FederationManager federationManager, string providerName) { return(federationManager.ListProviders()[providerName]); }
protected SearchProvider GetProviderByName(FederationManager federationManager, string providerName) { return federationManager.ListProviders()[providerName]; }