Nuta
Dostęp do tej strony wymaga autoryzacji. Możesz spróbować zalogować się lub zmienić katalogi.
Dostęp do tej strony wymaga autoryzacji. Możesz spróbować zmienić katalogi.
Dotyczy:SQL Server
Azure SQL Database
Azure SQL Managed Instance
Azure Synapse Analytics
SQL database w usłudze Microsoft Fabric
Wyszukiwanie pełnotekstowe jest dostępne dla każdego wystąpienia programu SQL Server i jest reprezentowane przez obiekt SMO FullTextService . Obiekt FullTextService znajduje się w obiekcie Server . Służy do zarządzania opcjami konfiguracji usługi wyszukiwania pełnotekstowego firmy Microsoft. Obiekt FullTextCatalogCollection należy do Database obiektu i jest kolekcją FullTextCatalog obiektów reprezentujących wykazy pełnotekstowe zdefiniowane dla bazy danych. Dla każdej tabeli można zdefiniować tylko jeden indeks pełnotekstowy, w przeciwieństwie do normalnych indeksów. Jest to reprezentowane przez FullTextIndexColumn obiekt w Table obiekcie.
Aby utworzyć usługę wyszukiwania pełnotekstowego, musisz mieć katalog pełnotekstowy zdefiniowany w bazie danych i indeks wyszukiwania pełnotekstowego zdefiniowany w jednej z tabel w bazie danych.
Najpierw utwórz katalog pełnotekstowy w bazie danych, wywołując FullTextCatalog konstruktor i określając nazwę katalogu. Następnie utwórz indeks pełnotekstowy, wywołując konstruktor i określając tabelę, na której ma zostać utworzona. Następnie można dodać kolumny indeksu dla indeksu pełnotekstowego przy użyciu FullTextIndexColumn obiektu i podać nazwę kolumny w tabeli. Następnie ustaw CatalogName właściwość na utworzony wykaz. Na koniec wywołaj metodę Create i utwórz indeks pełnotekstowy w wystąpieniu programu SQL Server.
Example
Aby użyć dowolnego podanego przykładu kodu, musisz wybrać środowisko programowania, szablon programowania i język programowania, w którym ma zostać utworzona aplikacja. Aby uzyskać więcej informacji, zobacz Create a Visual C# SMO Project in Visual Studio .NET(Tworzenie projektu SMO w programie Visual Studio .NET).
Tworzenie usługi wyszukiwania Full-Text w Visual Basic
Ten przykład kodu tworzy katalog wyszukiwania w pełnym tekstie dla tabeli ProductCategory w przykładowej bazie danych AdventureWorks2025. Następnie tworzy indeks wyszukiwania pełnotekstowego w kolumnie ProductCategory Nazwa w tabeli. Indeks wyszukiwania pełnotekstowego wymaga, aby w kolumnie był już zdefiniowany unikatowy indeks.
' 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
Tworzenie usługi wyszukiwania Full-Text w programie Visual C#
Ten przykład kodu tworzy katalog wyszukiwania w pełnym tekstie dla tabeli ProductCategory w przykładowej bazie danych AdventureWorks2025. Następnie tworzy indeks wyszukiwania pełnotekstowego w kolumnie ProductCategory Nazwa w tabeli. Indeks wyszukiwania pełnotekstowego wymaga, aby w kolumnie był już zdefiniowany unikatowy indeks.
// 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();
}
}
Tworzenie usługi wyszukiwania Full-Text w programie PowerShell
Ten przykład kodu tworzy katalog wyszukiwania w pełnym tekstie dla tabeli ProductCategory w przykładowej bazie danych AdventureWorks2025. Następnie tworzy indeks wyszukiwania pełnotekstowego w kolumnie ProductCategory Nazwa w tabeli. Indeks wyszukiwania pełnotekstowego wymaga, aby w kolumnie był już zdefiniowany unikatowy indeks.
# 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()