Not
Åtkomst till den här sidan kräver auktorisering. Du kan prova att logga in eller ändra kataloger.
Åtkomst till den här sidan kräver auktorisering. Du kan prova att ändra kataloger.
gäller för:SQL Server
Azure SQL Database
Azure SQL Managed Instance
Azure Synapse Analytics
SQL-databas i Microsoft Fabric
Fulltextsökning är tillgänglig per instans av SQL Server och representeras i SMO av FullTextService objektet. Objektet FullTextService finns under serverobjektet . Den används för att hantera konfigurationsalternativen för Microsoft Full Text Search-tjänsten. Objektet FullTextCatalogCollection tillhör Database objektet och det är en samling FullTextCatalog objekt som representerar fulltextkataloger som definierats för databasen. Du kan bara ha ett fulltextindex definierat för varje tabell, till skillnad från vanliga index. Detta representeras av ett FullTextIndexColumn objekt i objektet Table .
Om du vill skapa en fulltextsökningstjänst måste du ha en fulltextkatalog definierad i databasen och ett fulltextsökningsindex som definierats på en av tabellerna i databasen.
Skapa först en fulltextkatalog i databasen genom att anropa FullTextCatalog konstruktorn och ange katalognamnet. Skapa sedan fulltextindexet genom att anropa konstruktorn och ange den tabell som den ska skapas på. Du kan sedan lägga till indexkolumner för fulltextindexet genom att använda FullTextIndexColumn objektet och ange namnet på kolumnen i tabellen. Ange CatalogName sedan egenskapen till den katalog som du har skapat. Anropa slutligen Create metoden och skapa fulltextindexet för instansen av SQL Server.
Example
Om du vill använda ett kodexempel som tillhandahålls måste du välja programmeringsmiljö, programmeringsmallen och programmeringsspråket för att skapa ditt program. Mer information finns i Skapa ett Visual C# SMO-projekt i Visual Studio .NET.
Skapa en Full-Text söktjänst i Visual Basic
Detta kodexempel skapar en fulltext-sökkatalog för ProductCategory tabellen i AdventureWorks2025:s exempeldatabas. Sedan skapas ett fulltextsökningsindex i kolumnen Namn i ProductCategory tabellen. Fulltextsökningsindexet kräver att det finns ett unikt index som redan har definierats i kolumnen.
' 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
Skapa en Full-Text söktjänst i Visual C#
Detta kodexempel skapar en fulltext-sökkatalog för ProductCategory tabellen i AdventureWorks2025:s exempeldatabas. Sedan skapas ett fulltextsökningsindex i kolumnen Namn i ProductCategory tabellen. Fulltextsökningsindexet kräver att det finns ett unikt index som redan har definierats i kolumnen.
// 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();
}
}
Skapa en Full-Text söktjänst i PowerShell
Detta kodexempel skapar en fulltext-sökkatalog för ProductCategory tabellen i AdventureWorks2025:s exempeldatabas. Sedan skapas ett fulltextsökningsindex i kolumnen Namn i ProductCategory tabellen. Fulltextsökningsindexet kräver att det finns ett unikt index som redan har definierats i kolumnen.
# 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()