Partager via


Implementing Thesaurus support in the catalog system

Sql Server 2005 now provides Thesaurus support through configurable xml files. In a nutshell  the Thesaurus feature allows you to search for synonyms of the search phrase or replace the search phrase with a replacement phrase and perform the search using the replacement phrase.  These synonyms and replacements can be configured using the xml files.See this link for configuring the xml files.

If you are using Sql Server 2005 as your Commerce Server database server then you can take advantage of this cool feature when performing catalog searches. 

As an example, suppose  that you have a Books catalog. Assume that Description is a fulltext searchable property in this catalog and that this catalog has various C# books. When performing a search on your site users might search for C# or "C Sharp". You can use the Thesaurus feature to allow searches for "C Sharp" to return C# books.

The first step is to edit the tsENU.xml file located in the SQL_Server_install_path\Microsoft SQL Server\MSSQL.1\MSSQL\FTDATA\ directory and add the following element to it

         <expansion>
                     <sub>C sharp</sub>
                     <sub>C#</sub>
          </expansion>   

 After you edit the xml file you will have to restart the "SQL Server FullText Search (MSSQLSERVER)"  service for the changes to take effect.

The following code sample demonstrates how to perform the catalog search to allow searches for "C Sharp" to return books containing C#:

CatalogSearch

catalogSearch = catalogContext.GetCatalogSearch();

catalogSearch.SearchOptions = new CatalogSearchOptions();

// Set appropriate search options

catalogSearch.SearchOptions.SetPaging(1,20);

catalogSearch.UseAdvancedFreeTextSearch =

true;

catalogSearch.AdvancedFreeTextSearchPhrase =

"FORMSOF(THESAURUS, \"C Sharp\")";

int totalRecords;

CatalogItemsDataSet searchResults = catalogSearch.Search(out totalRecords);

// Iterate through the search results

foreach(CatalogItemsDataSet.CatalogItem searchResult in searchResults.CatalogItems)

      Console.WriteLine(searchResult.CategoryName);

Comments

  • Anonymous
    June 17, 2006
    Vinayak Tadas [MSFT] has released a few really great posts on some the new catalog features found in Commerce Server 2007.

  • Anonymous
    June 17, 2006
    Two years back in this post on fulltext search in the catalog system, I had explained how fulltext searches...
  • Anonymous
    October 07, 2006
    Two years back in this post on fulltext search in the catalog system , I had explained how fulltext searches