使用语义搜索查找文档中的关键短语Find Key Phrases in Documents with Semantic Search

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

介绍如何在为统计语义索引配置的文档或文本列中查找关键短语。Describes how to find the key phrases in documents or text columns that are configured for statistical semantic indexing.

使用 SEMANTICKEYPHRASETABLE 在文档中查找关键短语Find the key phrases in documents with SEMANTICKEYPHRASETABLE

若要确定特定文档中的关键短语或确定包含特定关键短语的文档,可以查询函数 semantickeyphrasetable (Transact-SQL)To identify the key phrases in specific documents, or to identify documents that contain specific key phrases, query the function semantickeyphrasetable (Transact-SQL).

SEMANTICKEYPHRASETABLE 为与指定表中的列关联的那些关键短语返回包含零行、一行或多行的表。SEMANTICKEYPHRASETABLE returns a table with zero, one, or more rows for those key phrases associated with 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.

备注

在此版本中,对于语义搜索只将单个单词编入索引,多词短语 (ngrams) 未编入索引。In this release, only single words are indexed for semantic search; multi-word phrases (ngrams) are not indexed. 此外,相同单词的各种形式单独编入索引,例如,“computer”和“computers”单独编入索引。Also, various forms of the same word are indexed separately; for example, "computer" and "computers" are indexed separately.

有关 SEMANTICKEYPHRASETABLE 函数所需的参数和它返回的结果表的详细信息,请参阅 semantickeyphrasetable (Transact-SQL)For detailed information about the parameters required by the SEMANTICKEYPHRASETABLE function, and about the table of results that it returns, see semantickeyphrasetable (Transact-SQL).

重要

针对的列必须启用了全文索引和语义索引。The columns that you target must have full-text and semantic indexing enabled.

示例 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.

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

SEMANTICKEYPHRASETABLE 函数使用索引查找替代表扫描高效检索这些结果。The SEMANTICKEYPHRASETABLE function retrieves these results efficiently by using an index seek instead of a table scan.

示例 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.

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;  
GO