Nota
O acesso a esta página requer autorização. Pode tentar iniciar sessão ou alterar os diretórios.
O acesso a esta página requer autorização. Pode tentar alterar os diretórios.
Aplica-se a:SQL Server
Banco de Dados SQL do Azure
Instância Gerenciada SQL do Azure
Banco de Dados SQL do Azure Synapse Analytics
no Microsoft Fabric
A pesquisa de texto completo está disponível por instância do SQL Server e é representada no SMO pelo FullTextService objeto. O FullTextService objeto reside sob o objeto Server . Ele é usado para gerenciar as opções de configuração para o serviço Microsoft Full Text Search. O FullTextCatalogCollection objeto pertence ao Database objeto e é uma coleção de objetos que representam catálogos de texto completo definidos para o banco de FullTextCatalog dados. Você só pode ter um índice de texto completo definido para cada tabela, ao contrário dos índices normais. Isso é representado por um FullTextIndexColumn objeto no Table objeto.
Para criar um serviço de pesquisa de texto completo, você deve ter um catálogo de texto completo definido no banco de dados e um índice de pesquisa de texto completo definido em uma das tabelas no banco de dados.
Primeiro, crie um catálogo de texto completo no banco de dados chamando o FullTextCatalog construtor e especificando o nome do catálogo. Em seguida, crie o índice de texto completo chamando o construtor e especificando a tabela na qual ele deve ser criado. Em seguida, você pode adicionar colunas de índice para o índice de texto completo, usando o FullTextIndexColumn objeto e fornecendo o nome da coluna dentro da tabela. Em seguida, defina a CatalogName propriedade para o catálogo que você criou. Finalmente, chame o Create método e crie o índice de texto completo na instância do SQL Server.
Example
Para usar qualquer exemplo de código fornecido, você terá que escolher o ambiente de programação, o modelo de programação e a linguagem de programação na qual criar seu aplicativo. Para obter mais informações, consulte Criar um projeto SMO do Visual C# no Visual Studio .NET.
Criando um serviço de pesquisa de Full-Text no Visual Basic
Este exemplo de código cria um catálogo de pesquisa em texto completo para a ProductCategory tabela na base de dados de exemplo AdventureWorks2025. Em seguida, cria um índice de pesquisa de texto completo na coluna Nome na ProductCategory tabela. O índice de pesquisa de texto completo requer que haja um índice exclusivo já definido na coluna.
' 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
Criando um serviço de pesquisa de Full-Text no Visual C#
Este exemplo de código cria um catálogo de pesquisa em texto completo para a ProductCategory tabela na base de dados de exemplo AdventureWorks2025. Em seguida, cria um índice de pesquisa de texto completo na coluna Nome na ProductCategory tabela. O índice de pesquisa de texto completo requer que haja um índice exclusivo já definido na coluna.
// 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();
}
}
Criando um serviço de pesquisa de Full-Text no PowerShell
Este exemplo de código cria um catálogo de pesquisa em texto completo para a ProductCategory tabela na base de dados de exemplo AdventureWorks2025. Em seguida, cria um índice de pesquisa de texto completo na coluna Nome na ProductCategory tabela. O índice de pesquisa de texto completo requer que haja um índice exclusivo já definido na coluna.
# 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()