Exporting and importing search configuration settings in SharePoint
Get code examples that show you how to export and import customized search configuration settings. These settings include all customized query rules, result sources, result types, ranking models, and site search settings. SharePoint exposes this functionality through the Microsoft.Office.Server.Search.Portability namespace.You can also export customized search configuration settings from a Search service application (SSA) and import the settings to site collections and sites.
Note
You can't import customized search configuration settings to an SSA, or export the default search configuration settings.
Export search configuration settings
The following code shows how to use SearchConfigurationPortability to export your site's search configuration settings. The code uses an example site http://yoursite/sites/publishing1
, which you'd replace with your own site. fileName refers to the file where the search configuration settings are stored; owner specifies the SPWeb level at which the search configuration settings are obtained.
private static void Export(string fileName)
{
SPSite site = new SPSite("http://yoursite/sites/publishing1");
SearchConfigurationPortability conf = new SearchConfigurationPortability(site);
SearchObjectOwner owner = new SearchObjectOwner(SearchObjectLevel.SPWeb, site.OpenWeb());
var buff = conf.ExportSearchConfiguration(owner);
File.WriteAllText(fileName, buff);
site.Close();
}
Import search configuration settings
The following code shows how to import search configuration settings from a file by using SearchConfigurationPortability and replace the existing search settings on a specified site, http://yoursite/sites/publishing1
. fileName refers to the file where the search configuration settings are stored; owner specifies the SPWeb level at which the search configuration settings are obtained.
private static void Import(string fileName)
{
SPSite site = new SPSite("http://yoursite/sites/publishing1");
SearchConfigurationPortability conf = new SearchConfigurationPortability(site);
SearchObjectOwner owner = new SearchObjectOwner(SearchObjectLevel.SPWeb, site.OpenWeb());
conf.ImportSearchConfiguration(owner, File.ReadAllText(fileName));
site.Close();
}
See also
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기