Full Text Search in SQL Server 2008
Introduction
SQL Server 2008 Full-Text Search feature can be used by application developers to execute full-text search queries against character based data residing in a SQL Server table. To use full text search the developer must create a full-text index for the table against which they want to run full-text search queries. For a particular SQL Server Table or Indexed View you can create a maximum of one Full-Text Index. The full-text index can be created for columns which use any of the following data types - CHAR, NCHAR, VARCHAR, NVARCHAR, TEXT, NTEXT, VARBINARY, VARBINARY (MAX), IMAGE and XML.Each full-text index can be used to index one or more columns from the base table, and each column can have a specific language which is supported by SQL Server 2008 Full-Text Search. Full-Text Search in SQL Server 2008 supports more than 50 different languages such as Arabic, Chinese, English, Japanese and Spanish etc.
For the complete list of supported full-text languages, run the below TSQL query.
Use master
GO
SELECT * FROM sys.fulltext_languages ORDER BY name ASC
GO
Installing Full-Text Search
The Full-Text Search feature of SQL Server 2008 is an optional component the Database Engine and as a result this feature is not installed by default. During SQL Server 2008 Installation, the database administrator needs to select the Full-Text Search feature as shown below :
In case Full-Text feature is not
available on the server then the DBA can install this feature by running the
SQL Server 2008 setup again and selecting the “New SQL
Server stand-alone installation or add feature to an existing installation”
option under Installation (as shown below).
If you are new to SQL Server 2008 and would like
to know how to steps which you need to follow in order to install SQL Server
2008 then please review the Steps
to install SQL Server 2008 article.
Once the full-text search feature is successfully installed on the
server you will be able to see SQL Full-text Filter Daemon
Launcher service in the SQL Server 2008 Configuration Manager. Make
sure this service is started before attempting to use Full-Text Search or the
queries will fail.
Steps to Configure a Database for Full-Text Search
Configure Full Text Search for a particular table with in a database by
following the below steps. In this article we will examine each step in detail.- Create a Full-Text Catalog
·
Create a Full-Text Index
·
Populate a Full-Text Index
Create a Full-Text Catalog
Create a Full-Text Index
Once you have successfully created a Full-Text Catalog, the next step is to create a Full-Text Index. In this example, we will be creating a Full-Text Index on the HumanResources.Employee table of the AdventureWorks database. Note that you can create only one full-text index on a particular SQL Server table.
1. Right click the HumanResources.Employee table and select Full-Text Index and choose Define Full-Text Index… as shown below to open the Full-Text Indexing Wizard.
5. In the Select Change Tracking wizard screen, select a change tracking method (see below). When you define automatic or manual change tracking, the full population of the index starts immediately once the wizard is complete. To avoid a full population at the end of the wizard you need to choose Do not track changes option and uncheck the Start full population when index is created check box as shown below. Click Next to continue.
9.
You will be shown a success message once the full-text index is configured
successfully :
Populate a Full-Text Index
The final step before you can start using Full-Text Search Queries is to Populate the Full-Text Index. This can be done by right clicking the HumanResources.Employee table and selecting Full-Text Index > Start Full Population as shown below.
You will be shown a success message once the Full-Text Index Population is completed successfully:
FREETEXT
Predicate
Use the FREETEXT predicate in a WHERE clause to search
columns containing character based data types, this find matches for the
meaning of the word(s) and not just the exact text in the search condition.
When FREETEXT is used, the SQL Server Query engine internally assigns each term
a weight and then finds the matches.
CONTAINS
Predicate
Use the CONTAINS predicate in a WHERE clause to search columns containing character based data types for precise or less precise matches to a single words or phrases. If you want to combine different words within a search, then you need to use conditions such as AND, OR etc within the search queries.
Below are some of the examples of full-text search queries which can be run against theHumanResources.Employee table in AdventureWorks.
USE AdventureWorks
GO
SELECT EmployeeID, Title
FROM HumanResources.Employee
WHERE FREETEXT(*, 'Recruiter')
GO
FROM HumanResources.Employee
WHERE CONTAINS ([Title], 'Recruiter OR Manager')
GO
Is this the Work Around or Best Solution?
Yes this is Best
Solution.
Comments
Post a Comment