Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Die Volltextsuche ist pro Instanz von SQL Server verfügbar und wird in SMO durch das FullTextService Objekt dargestellt. Das FullTextService Objekt befindet sich unter dem Server Objekt. Sie wird verwendet, um die Konfigurationsoptionen für den Volltextsuchdienst von Microsoft zu verwalten. Das FullTextCatalogCollection Objekt gehört zum Database Objekt, und es handelt sich um eine Auflistung von FullTextCatalog Objekten, die Volltextkataloge darstellen, die für die Datenbank definiert sind. Im Gegensatz zu normalen Indizes kann nur ein Volltextindex für jede Tabelle definiert werden. Dies wird durch ein FullTextIndexColumn Objekt im Table Objekt dargestellt.
Um einen Volltext-Suchdienst zu erstellen, müssen Sie einen Volltextkatalog in der Datenbank und einen Volltext-Suchindex für eine der Tabellen in der Datenbank definiert haben.
Erstellen Sie zunächst einen Volltextkatalog für die Datenbank, indem Sie den FullTextCatalog Konstruktor aufrufen und den Katalognamen angeben. Erstellen Sie dann den Volltextindex, indem Sie den Konstruktor aufrufen und die Tabelle angeben, auf der sie erstellt werden soll. Sie können dann Indexspalten für den Volltextindex hinzufügen, indem Sie das FullTextIndexColumn Objekt verwenden und den Namen der Spalte in der Tabelle angeben. Legen Sie dann die CatalogName Eigenschaft auf den katalog fest, den Sie erstellt haben. Rufen Sie schließlich die Create Methode auf, und erstellen Sie den Volltextindex für die Instanz von SQL Server.
Beispiel
Um ein codebeispiel zu verwenden, das bereitgestellt wird, müssen Sie die Programmierumgebung, die Programmiervorlage und die Programmiersprache auswählen, in der Ihre Anwendung erstellt werden soll. Weitere Informationen finden Sie unter Erstellen eines Visual Basic-SMO-Projekts in Visual Studio .NET oder Erstellen eines Visual C#-SMO-Projekts in Visual Studio .NET.
Erstellen eines Full-Text Suchdiensts in Visual Basic
In diesem Codebeispiel wird ein Volltext-Suchkatalog für die ProductCategory Tabelle in der AdventureWorks2012-Beispieldatenbank erstellt. Anschließend wird ein Volltext-Suchindex in der Spalte "Name" in der ProductCategory Tabelle erstellt. Der Volltext-Suchindex erfordert, dass in der Spalte bereits ein eindeutiger Index definiert ist.
' 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
Erstellen eines Full-Text Suchdiensts in Visual C#
In diesem Codebeispiel wird ein Volltext-Suchkatalog für die ProductCategory Tabelle in der AdventureWorks2012-Beispieldatenbank erstellt. Anschließend wird ein Volltext-Suchindex in der Spalte "Name" in der ProductCategory Tabelle erstellt. Der Volltext-Suchindex erfordert, dass in der Spalte bereits ein eindeutiger Index definiert ist.
// 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();
}
}
Erstellen eines Full-Text Suchdiensts in PowerShell
In diesem Codebeispiel wird ein Volltext-Suchkatalog für die ProductCategory Tabelle in der AdventureWorks2012-Beispieldatenbank erstellt. Anschließend wird ein Volltext-Suchindex in der Spalte "Name" in der ProductCategory Tabelle erstellt. Der Volltext-Suchindex erfordert, dass in der Spalte bereits ein eindeutiger Index definiert ist.
# 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()