Monday, October 19, 2015

How to create and import thesaurus in SharePoint Server

Before deep dive into how to create and import first we will discuss about thesaurus

What is Thesaurus?

Its same as synonym or as per google :) "a book that lists words in groups of synonyms and related concepts"

Before jump into the details, we will make clear that it will be used in sharepoint search.

Why it is  important in sharepoint world?

As explained above this is used in sharepoint search, so many people can search for the same data using different key world.

ex: If user wants to search for Laptop, then the user can try with different keywords like shown below :

Lap top
Laptop
Laptops
Lappy
Lap-top

In all of the above cases its referring to Laptop only, but how our sharepoint will understand these keys will be explained in the post

The situation becomes even difficult when people use acronyms :(

ex: HD TV
Hi Definition TV etc

In all of the above cases, search doesn't return any of the record even when user is referring to the same type/record

How to overcome this issue?

In Sharepoint 2013 we can easily create and upload the thesaurus(csv format) that contains synonyms for search phrases and acronym as well.

How to create it?

First we need to identify which are thesaurus we need to use in the system like as explained for Laptop example

1) Then open notepad(We can use CSV also)

2)  In the notepad enter the columns name like Key,Synonym,Language
Note: It should be at the top and there is no  space between 3 words and it should be separated  by comma.
ex:Key,Synonym,Language









3) In the text editor add new line and enter a term or a phrase, a synonym for that term or phrase and a two letter language code. Use commas to separate the phrases, for example Lap-top,Laptop,en

Note: Here Language is optional 

Repeat the same steps for entering multiple term as like below

Lap top,Laptop,en
Laptop,Laptop,en
Laptops,Laptop,en
Lappy,Laptop,en
Lap-top,Laptop,en
Lap Top,Laptop,en
Lap Tops,Laptop,en

Save the file as .csv with UTF-8 encoding.

Now our thesaurus are ready for importing into Sharepoint.









How to import into sharepoint environment?

1) Open a SharePoint 2013 Management Shell with Admin account(Search service application administrator)

2) In the command prompt  enter  the  following command

$searchApp = Get-SPEnterpriseSearchServiceApplication 
Import-SPEnterpriseSearchThesaurus -SearchApplication $searchApp -Filename \\sharepoint2013\\D$\Searchthesaurus\Thesaurus.csv

Here file path is given in the UNC format. This commandlet expects the file path in this format.






Now our thesaurus are part of search, even if the user search for any of the term search will return the proper results

Things to consider:

When we import  the thesaurus  existing  thesaurus will be overwritten.

There is no export functionality to take backup of the  existing thesaurus
(Its good to maintain the thesaurus files in external system where we can update the new thesaurus)

After  importing  thesaurus it will reflect  immediately, there is no delay in reflection

Its always better to update the existing copy of the thesaurus file so that all old entries will be available.

Issue might encounter  and steps to fix the issue

1) If we run the commandlet without admin access it might throw exception

2) Search needs to be properly configured

3) Make sure whatever term you are mapping its coming in the search result or not before running the scripts
ex: Laptop word  is coming or not please verify before running this.

4) After running the commandlet if you are seeing the below error in ULS then we need to restart Search and Timer service
Failed to start the flow: Microsoft.ThesaurusDeployment. Exception: System.ServiceModel.FaultException: Cannot start flow. The admin service is unavailable.

5) Make sure Primary host controller is enabled in the front end server where this scripts is running












1 comment:

  1. Please clarify your comment "There is export functionality to take backup of the existing thesaurus." Per https://technet.microsoft.com/en-us/library/dn794201.aspx, "You can’t export a thesaurus file."

    ReplyDelete