Poznámka:
Přístup k této stránce vyžaduje autorizaci. Můžete se zkusit přihlásit nebo změnit adresáře.
Přístup k této stránce vyžaduje autorizaci. Můžete zkusit změnit adresáře.
platí pro:SQL Server
Azure SQL Database
Azure SQL Managed Instance
Azure Synapse Analytics
sql database v Microsoft Fabric
Fulltextové vyhledávání je k dispozici na instanci SQL Serveru a je reprezentováno objektem FullTextService SMO. Objekt FullTextService se nachází pod objektem Server . Slouží ke správě možností konfigurace pro službu Microsoft Full Text Search. Objekt FullTextCatalogCollection patří k objektu Database a jedná se o kolekci FullTextCatalog objektů, které představují fulltextové katalogy definované pro databázi. Pro každou tabulku můžete definovat pouze jeden fulltextový index, na rozdíl od normálních indexů. Tento objekt je reprezentován FullTextIndexColumn objektem v objektu Table .
Chcete-li vytvořit fulltextovou vyhledávací službu, musíte mít definovaný fulltextový katalog pro databázi a index fulltextového vyhledávání definovaný na jedné z tabulek v databázi.
Nejprve vytvořte v databázi fulltextový katalog zavoláním konstruktoru FullTextCatalog a zadáním názvu katalogu. Pak vytvořte fulltextový index voláním konstruktoru a zadáním tabulky, na které se má vytvořit. Pak můžete přidat indexové sloupce pro fulltextový index pomocí objektu FullTextIndexColumn a zadáním názvu sloupce v tabulce. Potom nastavte CatalogName vlastnost na katalog, který jste vytvořili. Nakonec zavolejte metodu Create a vytvořte fulltextový index instance SQL Serveru.
Example
Pokud chcete použít libovolný zadaný příklad kódu, budete muset zvolit programovací prostředí, programovací šablonu a programovací jazyk, ve kterém chcete vytvořit aplikaci. Další informace najdete v tématu Vytvoření projektu SMO visual C# v sadě Visual Studio .NET.
Vytvoření vyhledávací služby Full-Text v jazyce Visual Basic
Tento příklad kódu vytváří katalog ProductCategory pro vyhledávání v celé textové tabulce v databázi AdventureWorks2025. Potom vytvoří fulltextový index vyhledávání ve sloupci Název v ProductCategory tabulce. Index fulltextového vyhledávání vyžaduje, aby byl ve sloupci již definovaný jedinečný index.
' 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
Vytvoření vyhledávací služby Full-Text v jazyce Visual C#
Tento příklad kódu vytváří katalog ProductCategory pro vyhledávání v celé textové tabulce v databázi AdventureWorks2025. Potom vytvoří fulltextový index vyhledávání ve sloupci Název v ProductCategory tabulce. Index fulltextového vyhledávání vyžaduje, aby byl ve sloupci již definovaný jedinečný index.
// 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();
}
}
Vytvoření vyhledávací služby Full-Text v PowerShellu
Tento příklad kódu vytváří katalog ProductCategory pro vyhledávání v celé textové tabulce v databázi AdventureWorks2025. Potom vytvoří fulltextový index vyhledávání ve sloupci Název v ProductCategory tabulce. Index fulltextového vyhledávání vyžaduje, aby byl ve sloupci již definovaný jedinečný index.
# 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()