Blog Pages

FullText Search

EXEC sp_fulltext_database 'enable' --Enabled the fulltext on the database
EXEC sp_fulltext_column 'tt', 'nn', 'add' -- tt - table, nn - column

http://amitpatriwala.wordpress.com/2008/08/11/fulltext-search-in-sqlserver-2005/

-- Enable full-text searching in the database.
EXEC sp_fulltext_database 'enable'
GO

-- Create a new full-text catalog.
EXEC sp_fulltext_catalog 'StevenBCatalog', 
                         'create' 
GO

-- Register the new table and column within it for full-text querying, 
-- then activate the table.
EXEC sp_fulltext_table 'FulltextTest', 
                       'create', 
                       'StevenBCatalog', 
                       'PK_title_id'
EXEC sp_fulltext_column 'FulltextTest', 
                        'article_title', 
                        'add'
EXEC sp_fulltext_table 'FulltextTest', 
                       'activate'
GO

-- Start full population of the full-text catalog. Note that it is
-- asynchronous, so delay must be built in if populating a
-- large index.

EXEC sp_fulltext_catalog 'StevenBCatalog', 
                         'start_full'
WHILE (SELECT fulltextcatalogproperty('StevenBCatalog',
'populatestatus')) <> 0
   BEGIN
      WAITFOR DELAY '00:00:02'     -- Check
      every 2 seconds to see if full-text index population is complete.
   CONTINUE
END

GO

-- Execute a full-text query against the new table.
SELECT article_title
FROM FulltextTest
WHERE CONTAINS(article_title, ' "Steven Buchanan" AND "ice skating" ')

No comments:

Post a Comment