Aracılığıyla paylaş


Tam metin arama uygulama

Tam metin arama örneği başına mevcut SQL Serverve SMO tarafından temsil edilen FullTextServicenesnesini. FullTextServiceAltında bulunan nesne Servernesnesini. Bu yapılandırma seçeneklerini yönetmek için kullanılan Microsofttam metin arama hizmeti. FullTextCatalogCollectionNesnesinin ait olduğu Databasenesne olup topluluğu FullTextCatalogtam-metin katalogları veritabanı için tanımlanan temsil eden nesneler. Yalnızca normal dizinler aksine her tablo için tanımlanmış bir tam metin dizin de olabilir. Bu temsil edilir bir FullTextIndexColumniçinde nesne Tablenesnesini.

Tam metin arama hizmeti oluşturmak için veritabanı tanımlanan bir tam metin kataloğu ve bir veritabanındaki tabloları üzerinde tanımlanmış bir tam metin arama dizin olması gerekir.

İlk olarak, bir tam metin kataloğu çağırarak veritabanı oluşturmak FullTextCatalogkurucusu ve katalog adı belirtme. Ardından, kurucusu ve tablonun oluşturulması olduğunu belirterek tam metin dizini oluşturun. Sonra dizin sütunları tam metin dizini kullanarak ekleyebileceğiniz FullTextIndexColumnnesnesi ve tablo içindeki sütun adını veren. Daha sonra CatalogNameözelliği için oluşturduğunuz katalog. Sonunda, Createyöntemi ve örneği üzerinde tam metin dizini oluşturma SQL Server.

Örnek

Sunulan kod örneklerinden herhangi birini kullanmak için, programlama ortamını, programlama şablonunu ve uygulamanızı oluşturacağınız programlama dilini seçmeniz gerekecektir. Daha fazla bilgi için, bkz. Visual Studio'da Visual Basic smo proje oluşturun.NET veya Visual Studio'da Visual C# smo proje oluşturun.NET.

Visual Basic'te bir tam metin arama hizmeti oluşturma

Bu kod örneği için tam metin arama kataloğu oluşturur ProductCategoryiçinde masa AdventureWorks2012örnek veritabanı. Daha sonra adı sütununda bir tam metin arama dizin oluşturur ProductCategorytablosu. Tam metin arama dizin zaten tanımlı sütun üzerinde 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 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

' 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

Tam metin arama hizmeti Visual C# içinde oluşturma

Bu kod örneği için tam metin arama kataloğu oluşturur ProductCategoryiçinde masa AdventureWorks2012örnek veritabanı. Daha sonra adı sütununda bir tam metin arama dizin oluşturur ProductCategorytablosu. Tam metin arama dizin zaten tanımlı sütun üzerinde 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 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();
   }
}

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

Tam metin arama hizmeti PowerShell içinde oluşturma

Bu kod örneği için tam metin arama kataloğu oluşturur ProductCategoryiçinde masa AdventureWorks2012örnek veritabanı. Daha sonra adı sütununda bir tam metin arama dizin oluşturur ProductCategorytablosu. Tam metin arama dizin zaten tanımlı sütun üzerinde 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 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()

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