Deploying search synonyms to SharePoint Search
SharePoint 2010 Search enables you to add search synonyms via XML configuration files on the server. The configuration is well described on TechNet and seems pretty straighforward. There are sample files in the installation, that you can use as a starting point, but straight away, we saw some challenges related to governance and deployment:
- Manual editing of XML files only works for really small files
- Deployment is cumbersome - it must be done on each server, and the path includes GUIDs
We therefore decided to script the rollout, taking a CSV file as input. CSV is easily edited using Excel, and PowerShell is great at parsing CSV and writing XML. This way, both problems could be easily solved. But, as we started trying this out, we ran into additional challenges:
- Adding anything except letters, numbers and spaces seem to breaks the feature
- In some environments, the reference to the XML schema causes problems
- Duplicate synonym entries makes the feature fail silently (this caused us a lot of headache…)
- We needed to log onto each individual search server to restart it
The XML schema problem appears in the event viewer and looks like this:
We found that removing the XML namespace reference at the start of the XML file solved the problem.
To make a long story short, we have created a script which handles everything you need:
- Converts CSV to XML
- Replaces, &, :, ;, etc. with spaces
- Barfs at you if you have duplicates
- Looks up the correct guid-folders for your servers
- Distributes the XML files
- Does an automatic restart of the OSearch14 windows service on all servers listed
Configuration is done via a simple PowerShell file which is passed as input to the main script. A couple of things to note regarding configuration:
- An arbitrary number of columns can be added - just make sure to add corresponding dummy-headings. Headings are required for PowerShell to parse the CSV properly.
- Deploying to "tsneu" is probably sufficient, as is done in the supplied config, but you can add a list of languages if needed.
Download the attached zip for the complete source. Thanks to my colleague Stig Lytjohan for doing much of the hard work!