Thursday, July 24, 2008    
Home My Books Blog ColdFusion About Me Back    

Calendar
<< Jan 2007 >>
S M T W T F S
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      

Search

Categories
 • Adobe (63) [RSS]
 • AdobeMAX06 (45) [RSS]
 • AdobeMAX07 (59) [RSS]
 • AdobeMAX08 (14) [RSS]
 • AIR (116) [RSS]
 • Appearances (115) [RSS]
 • Books (67) [RSS]
 • CFEclipse (14) [RSS]
 • ColdFusion (1120) [RSS]
 • Data Services (8) [RSS]
 • Flash (95) [RSS]
 • Flex (345) [RSS]
 • Jobs (88) [RSS]
 • JRun (12) [RSS]
 • Labs (27) [RSS]
 • LiveCycle (17) [RSS]
 • MAX (149) [RSS]
 • Regular Expressions (12) [RSS]
 • SQL (36) [RSS]
 • Stuff (498) [RSS]
 • Tips (CF Studio) (80) [RSS]
 • Tips (CF) (795) [RSS]
 • Tips (Dreamweaver) (91) [RSS]
 • Tips (Flex Builder) (2) [RSS]
 • Using CF (133) [RSS]
 • Wireless (97) [RSS]

Other BLOGs
 • Charlie Arehart
 • Lee Brimelow
 • Ray Camden
 • Christophe Coenraets
 • Sean Corfield
 • Mihai Corlan
 • Cornel Creanga
 • John Dowdell
 • Danny Dura
 • Enrique Duvos
 • Steven Erat
 • Kevin Hoyt
 • Serge Jespers
 • Adam Lehman
 • Duane Nickull
 • Miti Pricope
 • Andrew Shorten
 • Ryan Stewart
 • James Ward
 • Greg Wilson
 • Full As A Goog

RSS Feeds
 • Feed
 • Subscribe

Join my mailing list and find out about new books and other topics of interest.

Thoughts, ideas, tips, musings, and pontifications (not necessarily in that order) by Ben Forta ...
NOTE: This is my personal blog, and the opinions and statements voiced here are my own.

Viewing By Entry / Main
January 4, 2007

Setting Up SQL Server 2005 Full-Text Searching

SQL Server 2005 features an integrated full-text search engine, which several people have e-mailed me to ask about recently. (ColdFusion users can use <cfquery> to perform queries using SQL Server full-text searches).

If you want to play with SQL Server 2005 full-text search capabilities, you need to do the following:

1) Once a database has been created, support for full-text must be enabled before any full-text operations can be performed. To enable full-text support the sp_fulltext_database stored procedure is used. This stored procedure updates the currently selected database, so be sure to USE the correct database before issuing this statement:

EXEC sp_fulltext_database 'enable';

If you are using SQL Server Management Studio and use the interactive New Database dialog to create your database, you can check the "Use full-text indexing" checkbox, which causes the above mentioned stored procedure to be automatically executed.

2) SQL Server stores full-text data in a catalog (a file that needs to be created). A single catalog can be used for multiple tables and indexes. If a catalog does not already exist, create one using CREATE FULLTEXT CATALOG:

CREATE FULLTEXT CATALOG my_catalog;

This creates a catalog named my_catalog in the default catalog location. To specify the actual file location the IN PATH attribute can be specified.

3) Once a catalog has been created you can define the actual full-text indexes for each table containing columns that you want searchable. Indexes are created using CREATE FULLTEXT INDEX like this:

CREATE FULLTEXT INDEX ON table(column)
KEY INDEX table_primary_key
ON my_catalog;

When creating a full-text index you specify the table and column to be indexed as table(column). More than one column may be indexed if needed, to do this simply specify the column names (comma delimited). The key with which to uniquely identify rows is required, and so KEY INDEX is used to provide the name of the table's primary key. And finally, the ON clause specifies the catalog to be used to store full-text data, and here the just created catalog is used (unless a default catalog has been defined).

Once set up, you'll be ready to use the CONTAINS and FREETEXT functions in your WHERE clauses to perform full-text searching.

TrackBacks
There are no trackbacks for this entry.

No trackback URL. Trackbacks are only allowed via interactive form.

Comments
Interesting! Do you know whether you have to manually re-index on insert/update/delete or whether SQL 2005 handles it for you (and if so whether per transaction, nightly, etc.)? Also any idea of the performance hit for larger tables with frequent updates if re-indexing is per transaction?
# Posted By Peter Bell | 1/4/07 5:23 PM
Peter, it's configurable actually. By default indexes are updated in real-time, but you can make it happen on demand )maybe a scheduled event, calling ALTER FULLTEXT CATALOG catalogName REBUILD;. You can check index build status with SELECT * FROM sys.fulltext_indexes;, and catalog with SELECT * FROM sys.fulltext_catalogs;. Checking the status lets you know if the indexing is up to date, in progress, etc.

--- Ben
# Posted By Ben Forta | 1/4/07 6:26 PM
Very cool - thanks. One more reason to consider porting to 2005!
# Posted By Peter Bell | 1/4/07 6:46 PM
There is always the "old" method of creating a verity collection on your database info, and then using that to search (depending on what you are trying to accomplish)...
# Posted By Rich Rein | 1/5/07 5:01 PM

  © Copyright 1997-2008 Ben Forta, All Rights Reserved