Thursday, September 19, 2013

Sharepoint 2013 search - Synonyms

What is sharepoint synonyms? It is a super secret ... buried deep under we cannot find the synonyms.. but don't worry I got you covered.

Synonyms import – Manual

The only way to input the synonyms in sharepoint 2013 is by using powerscripts.

There is no tool to view the existing synonyms in sharepoint 2013.

There are also no export feature to export the existing synonyms. 


If we need to add new synonyms we need to overwrite it with a new file.

Manual Steps to import Synonyms in sharepoint 2013 Pre-requisite :
Admin rights in destination machine
ImportSynonyms.csv  file

1.      Open the file existing synonyms system in excel and save as ImportSynonyms.csv  or create a new/obtain an existing csv file  and rename to ImportSynonyms.csv
2.      Open ImportSynonyms.csv  in a notepad and check if the entries have the format key, Note language is an optional field(en specified below in the example) and not every entry needs it
Key,Synonym,Language
IE,Internet Explorer
Internet Explorer,IE
                   UN,United Nations,en

3.      Search for the original term/first time in the file in yourwebsite.com
4.      Check the results.Take a screen shot or note down the experience
5.      Create a file share in the server c:\search\ and call it ‘Search’
6.      Allow read only rights to everyone to this folder
7.      Copy ImportSynonyms.csv  to the folder c:\search\
8.      Change machinename to the servername and  Check if the UNC share is working \\machinename\search
9.      Change machinename to the servername and  Check if the UNC share is working \\machinename\search\ImportSynonyms.csv
10.   Go to Start /Run and type powershell.exe
11.   After it lauches the power shell prompt (which looks more like command prompt)
Change machinename to the servername and  copy paste the following  and press enter
Add-PSSnapin Microsoft.Sharepoint.Powershell
$searchApp = Get-SPEnterpriseSearchServiceApplication
Import-SPEnterpriseSearchThesaurus -SearchApplication $searchApp -Filename \\machinename\search\ImportSynonyms.csv  
12.   Search for the original term/first time in the file in yourwebsite.com ( same as step 2)
13.   Check the results.Take a screen shot or note down the experience(same as step 3)
14.   The result set must be different what was obtained earlier

Making Synonyms Visible

‘CloudMinder’ could have couple of  synonyms including “Cloud Minder” and “Cloud Security”
When we search documents with CloudMinder  (with no space) will appear first. If we want “Cloud Minder” and “Clou Security” to appear first (which is what we will need in most cases ) we need to do the following

1.      Login to the server
2.      Go to Start /Run and type powershell.exe
3.      After it lauches the power shell prompt (which looks more like command prompt)
copy paste the following  and press enter

Add-PsSnapin Microsoft.SharePoint.Powershell
& "C:\Program Files\Microsoft Office Servers\15.0\Search\Scripts\ceresshell.ps1"
Connect-System -Uri  (Get-SPEnterpriseSearchServiceApplication).SystemManagerLocations[0] -ServiceIdentity (Get-SPEnterpriseSearchService).ProcessIdentity
Connect-Engine -NodeTypes InterActionEngine
Get-Flow Microsoft.SharePointSearchProviderFlow > flowname.txt

4.      Locate flowname.txt
5.      Open the file in notepad
<Operator name="Linguistics" type="LinguisticQueryProcessing">
  <Property name="querySpellingCorrectionTokenLimit" value="10" />
.              <Property name="stemWeight" value="0.2" />
              
               <Property name="synonymWeight" value="0.2" />
              
               </Properties>
              
               </Operator>
6.      Change synonym weight to 1
7.      Go to Start /Run and type powershell.exe
8.      After it lauches the power shell prompt (which looks more like command prompt)
copy paste the following  and press enter

Remove-Flow Microsoft.SharePointSearchProviderFlow
Get-Content flowname.txt | Out-String | Add-Flow Microsoft.SharePointSearchProviderFlow
Stop-Flow –FlowName Microsoft.SharePointSearchProviderFlow –ForceAll



Scheduled Task

We can automate the whole task of importing Synonyms by ensuring we run the poweshell script on a periodic basis.

In Windows 7, press the “Win” key, and search the start menu for “Task”.  You may need to turn on administrative tools if it isn’t already on.

Follow these steps to add your ImportSynonyms.ps1  as a scheduled task (please refer to the section on importing Synonyms manually the script ImportSynonyms.ps1   is there!!!)

1.      Start the “Basic Task” wizard.
2.      “Create a Basic Task” – Give your task a name – “Sharepoint Synonyms Import” and description –“1. Use it to Import Coveo Synonyms (onetime) 2. Add new Synonyms”
3.      “Trigger” – Set to Daily and set the time to “1:30 AM”.
4.      “Action” – Set to Start a Program.  Program/Script is “PowerShell”.  Add argument for your script (“c:\search\ImportSynonym.ps1”)
5.      Finish

Screen shots below.

 















Synonym Change Process


Scheduled - Business needs to work with lT on an ongoing basis to provided updated index on a biweekly/monthly basis – A recurring change ticket needs to be created for this process

Manual - Business can provide ad-hoc Synonym files for an executive escalation or new acquisitons or new product launches or product updates or some unforeseen circumstance and GIS will execute the synonym script manually and update the Synonym

A/B testing Synonyms - For any experimental synonyms business can provide a synonym file that will be picked up every day morning (1:30am)  - This can be done on a Quarterly basis for 3 days.