SEMANTICSIMILARITYTABLE
SEMANTICSIMILARITYTABLE is a Transact-SQL table-valued function that returns a table with columns for matched similarity of all rows in a specified table. This function is used to find the statistical semantic similarity between the rows of a table based on the values in a specified columns. It is often used in full-text semantic indexing, to search for key phrases and documents that are similar to a specific text.
SEMANTICSIMILARITYTABLE( table, { column | (column_list) | * }, { registered_source_name, source_id | @source_string })
- table: This parameter represents the table on which the SEMANTICSIMILARITYTABLE function is applied. The table should have a full-text index with a registered semantic search key.
- {column|(column_list)|}: This parameter indicates the column or columns on which semantic search will be performed. The selected column or columns should be of type varchar(max), nvarchar(max), or varbinary(max). If ”*”, all full-text indexed columns are included.
- {registered_source_name, source_id|@source_string}: This parameter provides the specific document to be compared with other documents in the indexed table. ‘registered_source_name, source_id’ represents a row identifier from the indexed table. Alternatively, @source_string can be used to pass a string of type varchar(max), nvarchar(max), or varbinary(max).
Example
Output
Explanation
The SEMANTICSIMILARITYTABLE function returns a table of zero, one, or more rows for those columns containing character-based data types with values that are similar to a specified expression. The returned table has a RANK column and one column per uniqueidentifier rowset column in the indexed view. Each row contains the similarity rank and uniqueidentifier column values for a document that is similar to a specified document or document section. In the provided example, SEMANTICSIMILARITYTABLE is used to find the top 5 similar product descriptions to the product with ProductDescriptionID = 5.