FREETEXT (Transact-SQL)
Is a predicate used in the Transact-SQL WHERE clause of a Transact-SQL SELECT statement to perform a SQL Server full-text search on full-text indexed columns containing character-based data types. This predicate searches for values that match the meaning and not just the exact wording of the words in the search condition. When FREETEXT is used, the full-text query engine internally performs the following actions on the freetext_string, assigns each term a weight, and then finds the matches:
-
Separates the string into individual words based on word boundaries (word-breaking).
-
Generates inflectional forms of the words (stemming).
-
Identifies a list of expansions or replacements for the terms based on matches in the thesaurus.
Note
|
|---|
|
For information about the forms of full-text searches that are supported by SQL Server, see Query with Full-Text Search. |
Full-text predicates and functions work on a single table, which is implied in the FROM predicate. To search on multiple tables, use a joined table in your FROM clause to search on a result set that is the product of two or more tables.
Full-text queries using FREETEXT are less precise than those full-text queries using CONTAINS. The SQL Server full-text search engine identifies important words and phrases. No special meaning is given to any of the reserved keywords or wildcard characters that typically have meaning when specified in the <contains_search_condition> parameter of the CONTAINS predicate.
Full-text predicates are not allowed in the OUTPUT clause when the database compatibility level is set to 100.
Note
|
|---|
|
The FREETEXTTABLE function is useful for the same kinds of matches as the FREETEXT predicate. You can reference this function like a regular table name in the FROM clause of a SELECT statement. For more information, see FREETEXTTABLE (Transact-SQL). |
You can use a four-part name in the CONTAINS or FREETEXT predicate to query full-text indexed columns of the target tables on a linked server. To prepare a remote server to receive full-text queries, create a full-text index on the target tables and columns on the remote server and then add the remote server as a linked server.
In contrast to full-text search, the LIKE Transact-SQL predicate works on character patterns only. Also, you cannot use the LIKE predicate to query formatted binary data. Furthermore, a LIKE query against a large amount of unstructured text data is much slower than an equivalent full-text query against the same data. A LIKE query against millions of rows of text data can take minutes to return; whereas a full-text query can take only seconds or less against the same data, depending on the number of rows that are returned.
A. Using FREETEXT to search for words containing specified character values
The following example searches for all documents containing the words related to vital, safety, components.
USE AdventureWorks2012; GO SELECT Title FROM Production.Document WHERE FREETEXT (Document, 'vital safety components' ); GO
B. Using FREETEXT with variables
The following example uses a variable instead of a specific search term.
USE AdventureWorks2012; GO DECLARE @SearchWord nvarchar(30); SET @SearchWord = N'high-performance'; SELECT Description FROM Production.ProductDescription WHERE FREETEXT(Description, @SearchWord); GO
Note