Understanding Full Text Search in SQL Server 2005
page 5 of 7
by Uday Denduluri
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 21564/ 441

Running the Full Text search

Until now, we have set-up the full text search catalogues and indexes. Let us run the some queries for the full-text search. There are four types of predicates used in SQL Server 2005 for running the Full text search queries. A predicate is an expression that evaluates to TRUE, FALSE or UNKNOWN. A predicate is used in a where condition in T-SQL statement.

1.    FREETEXT

2.    FREETEXTTABLE

3.    CONTAINS

4.    CONTAINSTABLE

Let us see each one of them individually with its usage.

FREETEXT

Freetext is the simplest form of predicates in the full text search. It searches for the words that give the similar meaning and not the exact wording of the word. This kind of predicate is used where we go to query a document as a whole for a word in it. The freetext not only returns the exact wording, but also the nearest meanings attached to it. Listing 1 shows the usage of the free text. To understand listing 1, the user should have a basic understanding of T-SQL queries. Let us also see the usage of Freetext with a help of an example. Listing 2 gives an example for the usage of FREETEXT.

Listing 2

FREETEXT ( { column_name | (column_list) | * } 
          , 'freetext_string' [ , LANGUAGE language_term ] )

Listing 3

SELECT CellularPhone FROM CART WHERE FREETEXT (CellularPhone, '1111')

Listing 4

SELECT CELLULARPHONE FROM CART WHERE CELLULARPHONE LIKE '%1111%'

FREETEXTTABLE

Freetexttable returns a collection of one or more rows as a table. The columns in the rows are selected based on the string given as the predicate. Freetexttable is similar to freetext except the former can return tables and the latter one can return columns. Listing 4 shows the usage of Freetexttable.

Listing 5

FREETEXTTABLE (table , { column_name | (column_list) | * } 
          , 'freetext_string' 
     [ ,LANGUAGE language_term ] 
     [ ,top_n_by_rank ] )

CONTAINS

As the name suggests, Contains actually works by verifying if a word or phrase is contained in the columns. It can search for a word, prefix of a word, synonym of a word, word formed from another word. We need to specify the language in case the languages of the words are not of the same language. Listing 5 shows the simple usage of contains column.

Listing 6

SELECT [Name], [Address]
FROM Customer
WHERE AGE > 30
AND CONTAINS([Name], 'Uday');

CONTAINSTABLE

Contains and Containstable are similar to freetext and freetexttable. The former one returns columns and the latter one returns the table.


View Entire Article

Article Feedback

Title:  
Name:  
Url: ( Optional )
Comment:  
Please add 3 and 8 and type the answer here:

User Comments

Title: Understanding Full Text Search in SQL Server 2005   
Name: Sanjeev
Date: 11/13/2008 12:24:53 PM
Comment:
Good article for Beginers , Thanks for sharing .
Please explain other advanced topics soon in full text .

Thanks
Title: make it simple   
Name: Neela
Date: 11/1/2008 12:26:48 AM
Comment:
want to make catalogue for differant cat.please explain in simple language
Title: Try to explain more next time....   
Name: WebEye
Date: 9/5/2008 11:48:52 PM
Comment:
Try to explain more next time....
Title: Mr.   
Name: Hitesh
Date: 7/30/2008 12:37:47 PM
Comment:
Good Article.
Title: Usless   
Name: Programmer
Date: 7/8/2008 5:02:18 AM
Comment:
More details please
Title: Mr   
Name: Prasad
Date: 5/7/2008 2:34:49 PM
Comment:
Good Article for beginers
Title: Mr   
Name: khodor
Date: 4/21/2008 4:52:41 PM
Comment:
it is a good in general but i want more example about freetext table and containstable
Title: SQL Full Text Search - storage   
Name: Jack Kangas
Date: 12/24/2007 3:46:39 PM
Comment:
You mention that section on MSFTESQL (a windows service) - manages "the full text catalogs taht are stored within SQL Server"

I just created an index and there is now 75 meg of files in a catalog folder on the machine. What is in those .ci, .dir and .wid files?

I am asking because I am concerned about security on the words that are in the full text index. If anyone could read the words in those files (that are external to SQL Server's normal MDB, NDB, and LDB files.
Title: SQL Full Text Search   
Name: Saurabh Sharma
Date: 12/9/2007 11:52:07 PM
Comment:
Another gr8 one article.
Title: SQL Full Text Search   
Name: SAuarbh Sharma Software Engineer.
Date: 12/9/2007 11:50:47 PM
Comment:
It's Really Helpful and gr8 article. Thanx.
Title: SQL Full Text Search   
Name: Nitin Sharma Software Engineer
Date: 12/3/2007 10:53:50 PM
Comment:
Great one..!!






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2009 ASPAlliance.com  |  Page Processed at 1/8/2009 1:08:25 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search