--- title: "Implementing Full-Text Search | Microsoft Docs" ms.custom: "" ms.date: "08/06/2017" ms.prod: "sql-server-2016" ms.reviewer: "" ms.suite: "" ms.technology: - "docset-sql-devref" ms.tgt_pltfrm: "" ms.topic: "reference" helpviewer_keywords: - "full-text search [SMO]" ms.assetid: 9ce9ad9c-f671-4760-90b5-e0c8ca051473 caps.latest.revision: 47 author: "BYHAM" ms.author: "rickbyh" manager: "jhubbard" --- # Implementing Full-Text Search Full-text search is available per instance of [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] and is represented in SMO by the object. The object resides under the **Server** object. It is used to manage the configuration options for [!INCLUDE[msCoName](../../../includes/msconame-md.md)] Full Text Search service. The object belongs to the object and it is a collection of objects that represent full-text catalogs defined for the database. You can only have one full-text index defined for each table, unlike normal indexes. This is represented by a object in the object. To create a full-text search service, you must have a full-text catalog defined on the database and a full-text search index defined on one of the tables in the database. First, create a full-text catalog on the database by calling the constructor and specifying the catalog name. Then, create the full-text index by calling the constructor and specifying the table on which it is to be created. You can then add index columns for the full-text index, by using the object and providing the name of the column within the table. Then, set the property to the catalog you have created. Finally, call the method and create the full-text index on the instance of [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)]. ## Example To use any code example that is provided, you will have to choose the programming environment, the programming template, and the programming language in which to create your application. For more information, see [Create a Visual C# SMO Project in Visual Studio .NET](../../../relational-databases/server-management-objects-smo/how-to-create-a-visual-csharp-smo-project-in-visual-studio-net.md). ## Creating a Full-Text Search Service in Visual Basic This code example creates a full-text search catalog for the `ProductCategory` table in the [!INCLUDE[ssSampleDBnormal](../../../includes/sssampledbnormal-md.md)] sample database. It then creates a full-text search index on the Name column in the `ProductCategory` table. The full-text search index requires that there is a unique index already defined on the column. ``` ' compile with: ' /r:Microsoft.SqlServer.SqlEnum.dll ' /r:Microsoft.SqlServer.Smo.dll ' /r:Microsoft.SqlServer.ConnectionInfo.dll ' /r:Microsoft.SqlServer.Management.Sdk.Sfc.dll Imports Microsoft.SqlServer.Management.Smo Imports Microsoft.SqlServer.Management.Sdk.Sfc Imports Microsoft.SqlServer.Management.Common Public Class A Public Shared Sub Main() ' Connect to the local, default instance of SQL Server. Dim srv As Server = Nothing srv = New Server() ' Reference the AdventureWorks database. Dim db As Database = Nothing db = srv.Databases("AdventureWorks") ' Reference the ProductCategory table. Dim tb As Table = Nothing tb = db.Tables("ProductCategory", "Production") ' Define a FullTextCatalog object variable by specifying the parent database and name arguments in the constructor. Dim ftc As FullTextCatalog = Nothing ftc = New FullTextCatalog(db, "Test_Catalog") ftc.IsDefault = True ' Create the Full-Text Search catalog on the instance of SQL Server. ftc.Create() ' Define a FullTextIndex object varaible by supplying the parent table argument in the constructor. Dim fti As FullTextIndex = Nothing fti = New FullTextIndex(tb) ' Define a FullTextIndexColumn object variable by supplying the parent index and column name arguements in the constructor. Dim ftic As FullTextIndexColumn = Nothing ftic = New FullTextIndexColumn(fti, "Name") ' Add the indexed column to the index. fti.IndexedColumns.Add(ftic) fti.ChangeTracking = ChangeTracking.Automatic ' Specify the unique index on the table that is required by the Full Text Search index. fti.UniqueIndexName = "AK_ProductCategory_Name" ' Specify the catalog associated with the index. fti.CatalogName = "Test_Catalog" ' Create the Full Text Search index on the instance of SQL Server. fti.Create() End Sub End Class ``` ## Creating a Full-Text Search Service in Visual C# This code example creates a full-text search catalog for the `ProductCategory` table in the [!INCLUDE[ssSampleDBnormal](../../../includes/sssampledbnormal-md.md)] sample database. It then creates a full-text search index on the Name column in the `ProductCategory` table. The full-text search index requires that there is a unique index already defined on the column. ``` // compile with: // /r:Microsoft.SqlServer.SqlEnum.dll // /r:Microsoft.SqlServer.Smo.dll // /r:Microsoft.SqlServer.ConnectionInfo.dll // /r:Microsoft.SqlServer.Management.Sdk.Sfc.dll using Microsoft.SqlServer.Management.Smo; using Microsoft.SqlServer.Management.Sdk.Sfc; using Microsoft.SqlServer.Management.Common; public class A { public static void Main() { // Connect to the local, default instance of SQL Server. Server srv = default(Server); srv = new Server(); // Reference the AdventureWorks database. Database db = default(Database); db = srv.Databases ["AdventureWorks"]; // Reference the ProductCategory table. Table tb = default(Table); tb = db.Tables["ProductCategory", "Production"]; // Define a FullTextCatalog object variable by specifying the parent database and name arguments in the constructor. FullTextCatalog ftc = default(FullTextCatalog); ftc = new FullTextCatalog(db, "Test_Catalog"); ftc.IsDefault = true; // Create the Full-Text Search catalog on the instance of SQL Server. ftc.Create(); // Define a FullTextIndex object varaible by supplying the parent table argument in the constructor. FullTextIndex fti = default(FullTextIndex); fti = new FullTextIndex(tb); // Define a FullTextIndexColumn object variable by supplying the parent index and column name arguements in the constructor. FullTextIndexColumn ftic = default(FullTextIndexColumn); ftic = new FullTextIndexColumn(fti, "Name"); // Add the indexed column to the index. fti.IndexedColumns.Add(ftic); fti.ChangeTracking = ChangeTracking.Automatic; // Specify the unique index on the table that is required by the Full Text Search index. fti.UniqueIndexName = "AK_ProductCategory_Name"; // Specify the catalog associated with the index. fti.CatalogName = "Test_Catalog"; // Create the Full Text Search index on the instance of SQL Server. fti.Create(); } } ``` ## Creating a Full-Text Search Service in PowerShell This code example creates a full-text search catalog for the `ProductCategory` table in the [!INCLUDE[ssSampleDBnormal](../../../includes/sssampledbnormal-md.md)] sample database. It then creates a full-text search index on the Name column in the `ProductCategory` table. The full-text search index requires that there is a unique index already defined on the column. ``` # Example of implementing a full text search on the default instance. # Set the path context to the local, default instance of SQL Server and database tables CD \sql\localhost\default\databases $db = get-item AdventureWorks2012 CD AdventureWorks\tables #Get a reference to the table $tb = get-item Production.ProductCategory # Define a FullTextCatalog object variable by specifying the parent database and name arguments in the constructor. $ftc = New-Object -TypeName Microsoft.SqlServer.Management.SMO.FullTextCatalog -argumentlist $db, "Test_Catalog2" $ftc.IsDefault = $true # Create the Full Text Search catalog on the instance of SQL Server. $ftc.Create() # Define a FullTextIndex object variable by supplying the parent table argument in the constructor. $fti = New-Object -TypeName Microsoft.SqlServer.Management.SMO.FullTextIndex -argumentlist $tb # Define a FullTextIndexColumn object variable by supplying the parent index # and column name arguments in the constructor. $ftic = New-Object -TypeName Microsoft.SqlServer.Management.SMO.FullTextIndexColumn -argumentlist $fti, "Name" # Add the indexed column to the index. $fti.IndexedColumns.Add($ftic) # Set change tracking $fti.ChangeTracking = [Microsoft.SqlServer.Management.SMO.ChangeTracking]::Automatic # Specify the unique index on the table that is required by the Full Text Search index. $fti.UniqueIndexName = "AK_ProductCategory_Name" # Specify the catalog associated with the index. $fti.CatalogName = "Test_Catalog2" # Create the Full Text Search Index $fti.Create() ```