semantickeyphrasetable (Transact-SQL)semantickeyphrasetable (Transact-SQL)

适用对象: 是SQL Server 否Azure SQL 数据库 否Azure Synapse Analytics (SQL DW) 否并行数据仓库 APPLIES TO: yesSQL Server noAzure SQL Database noAzure Synapse Analytics (SQL DW) noParallel Data Warehouse

为与指定表中的指定列关联的关键短语返回包含零行、一行或多行的表。Returns a table with zero, one, or more rows for key phrases associated with the specified columns in the specified table.

可以在 SELECT 语句的 FROM 子句中像引用常规表名那样引用此行集函数。This rowset function can be referenced in the FROM clause of a SELECT statement as if it were a regular table name.

主题链接图标 TRANSACT-SQL 语法约定Topic link icon Transact-SQL Syntax Conventions

语法Syntax

SEMANTICKEYPHRASETABLE  
    (  
    table,  
    { column | (column_list) | * }  
     [ , source_key ]  
    )  

参数Arguments

tabletable
启用全文和语义索引的表的名称。Is the name of a table that has full-text and semantic indexing enabled.

此名称可由 1 到 4 个部分组成,但不允许使用远程服务器名称。This name can be a one to four part name, but a remote server name is not allowed.

columncolumn
应为其返回结果的索引列的名称。Name of the indexed column for which results should be returned. 列必须启用语义索引。Column must have semantic indexing enabled.

column_listcolumn_list
指示由逗号分隔并括在括号中的多个列。Indicates several columns, separated by a comma and enclosed in parentheses. 所有列都必须启用语义索引。All columns must have semantic indexing enabled.

*
指示已启用语义索引的所有列都均包括在内。Indicates that all columns that have semantic indexing enabled are included.

source_keysource_key
请求特定行的结果的行的唯一键。Unique key for the row, to request results for a specific row.

键隐式转换为尽可能与源表中的全文唯一键的类型。The key is implicitly converted to the type of the full-text unique key in the source table whenever possible. 可以将此键指定为一个常量或变量,但不能是表达式或标量子查询的结果。The key can be specified as a constant or a variable, but cannot be an expression or the result of a scalar sub-query. 如果省略 source_key,则返回所有行的结果。If source_key is omitted, then results are returned for all rows.

返回的表Table Returned

下表介绍此行集函数返回的关键短语的信息。The following table describes the information about key phrases that this rowset function returns.

Column_nameColumn_name typeType 描述Description
column_idcolumn_id intint 从中对当前关键短语提取并编制索引的列的 ID。ID of the column from which the current key phrase was extracted and indexed.

有关如何在列名称和 column_id 之间相互检索对方的详细信息,请参阅 COL_NAME 和 COLUMNPROPERTY 函数。See the COL_NAME and COLUMNPROPERTY functions for details on how to retrieve column name from column_id and vice versa.
document_keydocument_key *

此键与源表中的唯一键的类型相匹配。This key matches the type of the unique key in the source table.
从中对当前关键短语进行索引的文档或行的唯一键值。Unique key value of the document or row from which the current key phrase was indexed.
keyphrasekeyphrase NVARCHARNVARCHAR 在由 column_id 表示的列中找到的关键短语,与 document_key 指定的文档关联。The key phrase found in the column identified by column_id, and associated with the document specified by document_key.
scorescore REALREAL 一个相对值,用来表示此关键短语与索引列中同一文档的所有其他关键短语的关系。A relative value for this key phrase in its relationship to all the other key phrases in the same document in the indexed column.

该值是范围 [0.0, 1.0] 中的小数值,较高的得分表示较高权重,1.0 是最理想的得分。The value is a fractional decimal value in the range of [0.0, 1.0] where a higher score represents a higher weighting and 1.0 is the perfect score.

一般备注General Remarks

有关详细信息,请参阅使用语义搜索在文档中查找关键短语For more information, see Find Key Phrases in Documents with Semantic Search.

元数据Metadata

有关语义关键短语的提取和填充的信息和状态,请查询以下动态管理视图:For information and status about semantic key phrase extraction and population, query the following dynamic management views:

安全性Security

权限Permissions

需要对创建全文和语义搜索所基于的基表具有 SELECT 权限。Requires SELECT permissions on the base table on which the full-text and semantic indexes were created.

示例Examples

示例 1:查找特定文档中的最重要关键短语Example 1: Find the Top Key Phrases in a Specific Document

以下示例从通过 @DocumentId 变量指定的文档中检索前 10 个关键短语,该变量位于 AdventureWorks 示例数据库的 Production.Document 表的 Document 列中。The following example retrieves the top 10 key phrases from the document specified by the @DocumentId variable in the Document column of the Production.Document table of the AdventureWorks sample database. @DocumentId 变量表示全文检索的键列的一个值。The @DocumentId variable represents a value from the key column of the full-text index. SEMANTICKEYPHRASETABLE 函数使用索引查找替代表扫描高效检索这些结果。The SEMANTICKEYPHRASETABLE function retrieves these results efficiently by using an index seek instead of a table scan. 此示例假定列已配置为进行全文和语义索引。This example assumes that the column is configured for full-text and semantic indexing.

SELECT TOP(10) KEYP_TBL.keyphrase  
FROM SEMANTICKEYPHRASETABLE  
    (  
    Production.Document,  
    Document,  
    @DocumentId  
    ) AS KEYP_TBL  
ORDER BY KEYP_TBL.score DESC;  
  

示例 2:查找包含特定关键短语的最相关文档Example 2: Find the Top Documents that Contain a Specific Key Phrase

以下示例从 AdventureWorks 示例数据库的 Production.Document 表的 Document 列中检索包含关键短语“Bracket”的前 25 个文档。The following example retrieves the top 25 documents that contain the key phrase "Bracket" from the Document column of the Production.Document table of the AdventureWorks sample database. 此示例假定列已配置为进行全文和语义索引。This example assumes that the column is configured for full-text and semantic indexing.

SELECT TOP (25) DOC_TBL.DocumentID, DOC_TBL.DocumentSummary  
FROM Production.Document AS DOC_TBL  
    INNER JOIN SEMANTICKEYPHRASETABLE  
    (  
    Production.Document,  
    Document  
    ) AS KEYP_TBL  
ON DOC_TBL.DocumentID = KEYP_TBL.document_key  
WHERE KEYP_TBL.keyphrase = 'Bracket'  
ORDER BY KEYP_TBL.Score DESC;