Aracılığıyla paylaş


Full-Text Arama Uygulama

Şunlar için geçerlidir:SQL ServerAzure SQL VeritabanıAzure SQL Yönetilen ÖrneğiMicrosoft Fabric'de Azure Synapse AnalyticsSQL veritabanı

Tam metin araması SQL Server örneği başına kullanılabilir ve nesne tarafından FullTextService SMO'da gösterilir. Nesne, FullTextServiceSunucu nesnesinin altında yer alır. Microsoft Tam Metin Arama hizmetinin yapılandırma seçeneklerini yönetmek için kullanılır. FullTextCatalogCollection Nesnesi nesnesine Database aittir ve veritabanı için tanımlanan tam metin kataloglarını temsil eden bir nesne koleksiyonudurFullTextCatalog. Normal dizinlerden farklı olarak, her tablo için yalnızca bir tam metin dizini tanımlayabilirsiniz. Bu, nesnedeki FullTextIndexColumn bir Table nesneyle temsil edilir.

Tam metin arama hizmeti oluşturmak için, veritabanında tanımlanmış bir tam metin kataloğunuz ve veritabanındaki tablolardan birinde tanımlanmış bir tam metin arama dizininiz olmalıdır.

İlk olarak, oluşturucuyu çağırarak FullTextCatalog ve katalog adını belirterek veritabanında bir tam metin kataloğu oluşturun. Ardından, oluşturucuyu çağırarak ve oluşturulacağı tabloyu belirterek tam metin dizinini oluşturun. Ardından, nesnesini kullanarak FullTextIndexColumn ve tablodaki sütunun adını sağlayarak tam metin dizini için dizin sütunları ekleyebilirsiniz. Ardından, özelliğini oluşturduğunuz kataloğa ayarlayın CatalogName . Son olarak yöntemini çağırın Create ve SQL Server örneğinde tam metin dizinini oluşturun.

Example

Sağlanan herhangi bir kod örneğini kullanmak için programlama ortamını, programlama şablonunu ve uygulamanızın oluşturulacağı programlama dilini seçmeniz gerekir. Daha fazla bilgi için bkz. Visual Studio .NET'te Visual C# SMO Projesi Oluşturma.

Visual Basic'te Full-Text Arama Hizmeti Oluşturma

Bu kod örneği, AdventureWorks2025 örnek veritabanındaki tablo için tam metin bir arama kataloğu ProductCategory oluşturur. Ardından tablodaki Ad sütununda ProductCategory bir tam metin arama dizini oluşturur. Tam metin arama dizini, sütunda önceden tanımlanmış benzersiz bir dizin olmasını gerektirir.

' 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 variable 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'de Full-Text Arama Hizmeti Oluşturma#

Bu kod örneği, AdventureWorks2025 örnek veritabanındaki tablo için tam metin bir arama kataloğu ProductCategory oluşturur. Ardından tablodaki Ad sütununda ProductCategory bir tam metin arama dizini oluşturur. Tam metin arama dizini, sütunda önceden tanımlanmış benzersiz bir dizin olmasını gerektirir.

// 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 variable 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'de Full-Text Arama Hizmeti Oluşturma

Bu kod örneği, AdventureWorks2025 örnek veritabanındaki tablo için tam metin bir arama kataloğu ProductCategory oluşturur. Ardından tablodaki Ad sütununda ProductCategory bir tam metin arama dizini oluşturur. Tam metin arama dizini, sütunda önceden tanımlanmış benzersiz bir dizin olmasını gerektirir.

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