전체 텍스트 검색 구현

적용 대상:SQL ServerAzure SQL DatabaseAzure SQL Managed InstanceAzure Synapse Analytics

전체 텍스트 검색은 SQL Server 인스턴스별로 사용할 수 있으며 개체에 의해 SMO로 FullTextService 표시됩니다. 개체는 FullTextService Server 개체 아래에 있습니다. Microsoft 전체 텍스트 검색 서비스에 대한 구성 옵션을 관리하는 데 사용됩니다. 개체는 FullTextCatalogCollection 개체에 속하며 데이터베이스에 Database 대해 정의된 전체 텍스트 카탈로그를 나타내는 개체의 FullTextCatalog 컬렉션입니다. 일반 인덱스와 달리 각 테이블에 대해 하나의 전체 텍스트 인덱스만 정의할 수 있습니다. FullTextIndexColumn 개체에서 Table 개체로 표시됩니다.

전체 텍스트 검색 서비스를 만들려면 데이터베이스에 정의된 전체 텍스트 카탈로그와 데이터베이스의 테이블 중 하나에 정의된 전체 텍스트 검색 인덱스가 있어야 합니다.

먼저, FullTextCatalog 생성자를 호출하고 카탈로그 이름을 지정하여 데이터베이스에 전체 텍스트 카탈로그를 만듭니다. 그런 다음 생성자를 호출하고 생성할 테이블을 지정하여 전체 텍스트 인덱스 만들기 그런 다음 개체를 사용하고 FullTextIndexColumn 테이블 내의 열 이름을 제공하여 전체 텍스트 인덱스에 대한 인덱스 열을 추가할 수 있습니다. 그런 다음, 속성을 만든 카탈로그로 설정합니다 CatalogName . 마지막으로, 메서드를 Create 호출하고 SQL Server 인스턴스에서 전체 텍스트 인덱스 만들기

제공된 코드 예제를 사용하려면 프로그래밍 환경, 프로그래밍 템플릿 및 애플리케이션을 만들 프로그래밍 언어를 선택해야 합니다. 자세한 내용은 Visual Studio .NET에서 Visual C# SMO 프로젝트 만들기를 참조하세요.

Visual Basic에서 전체 텍스트 검색 서비스 만들기

이 코드 예제에서는 AdventureWorks2022 샘플 데이터베이스에서 테이블에 대한 ProductCategory 전체 텍스트 검색 카탈로그를 만듭니다. 그런 다음 테이블의 이름 열에 전체 텍스트 검색 인덱스가 ProductCategory 만들어집니다. 전체 텍스트 검색 인덱스를 사용하려면 열에 이미 정의된 고유 인덱스가 있어야 합니다.

' 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 arguments 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  

Visual C에서 전체 텍스트 검색 서비스 만들기#

이 코드 예제에서는 AdventureWorks2022 샘플 데이터베이스에서 테이블에 대한 ProductCategory 전체 텍스트 검색 카탈로그를 만듭니다. 그런 다음 테이블의 이름 열에 전체 텍스트 검색 인덱스가 ProductCategory 만들어집니다. 전체 텍스트 검색 인덱스를 사용하려면 열에 이미 정의된 고유 인덱스가 있어야 합니다.

// 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 arguments 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();  
   }  
}  

PowerShell에서 전체 텍스트 검색 서비스 만들기

이 코드 예제에서는 AdventureWorks2022 샘플 데이터베이스에서 테이블에 대한 ProductCategory 전체 텍스트 검색 카탈로그를 만듭니다. 그런 다음 테이블의 이름 열에 전체 텍스트 검색 인덱스가 ProductCategory 만들어집니다. 전체 텍스트 검색 인덱스를 사용하려면 열에 이미 정의된 고유 인덱스가 있어야 합니다.

# 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 AdventureWorks2022  
  
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()