|
1 | | ---- |
2 | | -title: Exporting and importing search configuration settings in SharePoint |
3 | | -description: 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. |
4 | | -ms.date: 09/25/2017 |
5 | | -ms.assetid: d00679a3-ffa2-4281-ad8b-70fc2c4a14e2 |
6 | | -ms.localizationpriority: medium |
7 | | ---- |
8 | | - |
9 | | - |
10 | | -# Exporting and importing search configuration settings in SharePoint |
11 | | -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](https://msdn.microsoft.com/library/Microsoft.Office.Server.Search.Portability.aspx) namespace.You can also export customized search configuration settings from a Search service application (SSA) and import the settings to site collections and sites. |
12 | | - |
13 | | -> [!NOTE] |
14 | | -> You can't import customized search configuration settings to an SSA, or export the default search configuration settings. |
15 | | -
|
16 | | - |
17 | | - |
18 | | - |
19 | | - |
20 | | -## Export search configuration settings |
21 | | -<a name="SP15_exporting_search_configuration"> </a> |
22 | | - |
23 | | -The following code shows how to use [SearchConfigurationPortability](https://msdn.microsoft.com/library/Microsoft.Office.Server.Search.Portability.SearchConfigurationPortability.aspx) 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](https://msdn.microsoft.com/library/Microsoft.SharePoint.SPWeb.aspx) level at which the search configuration settings are obtained. |
24 | | - |
25 | | - |
26 | | - |
27 | | - |
28 | | -``` |
29 | | -
|
30 | | -private static void Export(string fileName) |
31 | | -{ |
32 | | - SPSite site = new SPSite("http://yoursite/sites/publishing1"); |
33 | | - SearchConfigurationPortability conf = new SearchConfigurationPortability(site); |
34 | | - SearchObjectOwner owner = new SearchObjectOwner(SearchObjectLevel.SPWeb, site.OpenWeb()); |
35 | | - var buff = conf.ExportSearchConfiguration(owner); |
36 | | - File.WriteAllText(fileName, buff); |
37 | | - site.Close(); |
38 | | -} |
39 | | -``` |
40 | | - |
41 | | - |
42 | | -## Import search configuration settings |
43 | | -<a name="SP15_importing_search_configuration"> </a> |
44 | | - |
45 | | -The following code shows how to import search configuration settings from a file by using [SearchConfigurationPortability](https://msdn.microsoft.com/library/Microsoft.Office.Server.Search.Portability.SearchConfigurationPortability.aspx) 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](https://msdn.microsoft.com/library/Microsoft.SharePoint.SPWeb.aspx) level at which the search configuration settings are obtained. |
46 | | - |
47 | | - |
48 | | - |
49 | | - |
50 | | -```csharp |
51 | | - |
52 | | -private static void Import(string fileName) |
53 | | -{ |
54 | | - SPSite site = new SPSite("http://yoursite/sites/publishing1"); |
55 | | - SearchConfigurationPortability conf = new SearchConfigurationPortability(site); |
56 | | - SearchObjectOwner owner = new SearchObjectOwner(SearchObjectLevel.SPWeb, site.OpenWeb()); |
57 | | - conf.ImportSearchConfiguration(owner, File.ReadAllText(fileName)); |
58 | | - site.Close(); |
59 | | -} |
60 | | - |
61 | | -``` |
62 | | - |
63 | | - |
64 | | -## See also |
65 | | -<a name="bk_addresources"> </a> |
66 | | - |
67 | | - |
68 | | -- [Search in SharePoint](search-in-sharepoint.md) |
69 | | - |
70 | | - |
71 | | -- [Export and import customized search configuration settings in SharePoint](https://technet.microsoft.com/library/jj871675.aspx) |
72 | | - |
73 | | - |
74 | | - |
75 | | - |
76 | | - |
77 | | - |
78 | | - |
| 1 | +--- |
| 2 | +title: Exporting and importing search configuration settings in SharePoint |
| 3 | +description: 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. |
| 4 | +ms.date: 04/24/2017 |
| 5 | +ms.assetid: d00679a3-ffa2-4281-ad8b-70fc2c4a14e2 |
| 6 | +ms.localizationpriority: medium |
| 7 | +--- |
| 8 | + |
| 9 | +# Exporting and importing search configuration settings in SharePoint |
| 10 | + |
| 11 | +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](/previous-versions/office/sharepoint-server/jj268113(v=office.15)) namespace. You can also export customized search configuration settings from a Search service application (SSA) and import the settings to site collections and sites. |
| 12 | + |
| 13 | +> [!NOTE] |
| 14 | +> You can't import customized search configuration settings to an SSA, or export the default search configuration settings. |
| 15 | +
|
| 16 | +## Export search configuration settings |
| 17 | + |
| 18 | +The following code shows how to use [SearchConfigurationPortability](/previous-versions/office/sharepoint-server/jj267460(v=office.15)) 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](/previous-versions/office/sharepoint-server/ms473942(v=office.15)) level at which the search configuration settings are obtained. |
| 19 | + |
| 20 | +```csharp |
| 21 | +private static void Export(string fileName) |
| 22 | +{ |
| 23 | + SPSite site = new SPSite("http://yoursite/sites/publishing1"); |
| 24 | + SearchConfigurationPortability conf = new SearchConfigurationPortability(site); |
| 25 | + SearchObjectOwner owner = new SearchObjectOwner(SearchObjectLevel.SPWeb, site.OpenWeb()); |
| 26 | + var buff = conf.ExportSearchConfiguration(owner); |
| 27 | + File.WriteAllText(fileName, buff); |
| 28 | + site.Close(); |
| 29 | +} |
| 30 | +``` |
| 31 | + |
| 32 | +## Import search configuration settings |
| 33 | + |
| 34 | +The following code shows how to import search configuration settings from a file by using [SearchConfigurationPortability](/previous-versions/office/sharepoint-server/jj267460(v=office.15)) 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](/previous-versions/office/sharepoint-server/ms473942(v=office.15)) level at which the search configuration settings are obtained. |
| 35 | + |
| 36 | +```csharp |
| 37 | +private static void Import(string fileName) |
| 38 | +{ |
| 39 | + SPSite site = new SPSite("http://yoursite/sites/publishing1"); |
| 40 | + SearchConfigurationPortability conf = new SearchConfigurationPortability(site); |
| 41 | + SearchObjectOwner owner = new SearchObjectOwner(SearchObjectLevel.SPWeb, site.OpenWeb()); |
| 42 | + conf.ImportSearchConfiguration(owner, File.ReadAllText(fileName)); |
| 43 | + site.Close(); |
| 44 | +} |
| 45 | +``` |
| 46 | + |
| 47 | +## See also |
| 48 | + |
| 49 | +- [Search in SharePoint](search-in-sharepoint.md) |
| 50 | +- [Export and import customized search configuration settings in SharePoint](/SharePoint/search/export-and-import-customized-search-configuration-settings) |
0 commit comments