← Tutti gli articoli

Full-Text Searching - FTS - Sql Server 2008 R2

20 August 2010  ·  Sql Server 2008 · Article  ·  91 visite

Learn how to use SQL Server’s full-text searching capabilities to perform sophisticated data querying and selection.

Understanding Full-Text Searching

Wildcard Filtering Limitation
·  Performance: Like operator searches can be very time-consuming because Sql Server try to match for each row in the table
·  Explicit control
·  Intelligent results: the wildcard searching doesn’t provide an intelligent way to select the results (single match and multi matches are not distinguished.

Full text searching does not need to look at each row in the table because an index of the words (in a coloumn of the table)  is created in Sql Server.


Setting Up Full-Text Searching

Prerequisite for the full text searches:
·  Enable Full Text Search in the database:
·  Define a catalog (where full text data are stored)
·  Create an index for indexes coloumns and tables.
After  indexing you can use in your SELECT the predicates:
·  FREETEXT
·  FREETEXTTABLE

·  CONTAINS
·  CONTAINSTABLE
·  etc


Enabling Full-Text Searching Support

Enable full text searches
To enable full text searches for your database execute the following script:
  1. EXEC sp_fulltext_database 'enable';   
  2.   
  3. Creating a Full-Text Catalog    
  4. CREATE FULLTEXT CATALOG [MaragnaNetFullTextCatalog]WITH ACCENT_SENSITIVITY = ON  
  5. AS DEFAULT  
  6. AUTHORIZATION [dbo]   
  7.   
  8. Creating a Full-Text Index    
  9. CREATE FULLTEXT INDEX ON Contents(ContentTitle,ContentDescription)   
  10. KEY INDEX PK_Contents   
  11. ON [MaragnaNetFullTextCatalog];   
  12.   
  13. Where Contents is the table, ContentTitle and ContentDescription are the coloumns and PK_Contents is the table primary key name.   
  14.   
  15.   
  16. Populate the index  
  17. ALTER FULLTEXT CATALOG [MaragnaNetFullTextCatalog] REBUILD;   
  18.   
  19. Performing Full-Text Searches   
  20.   
  21. SELECT *    
  22. FROM Contents   
  23. WHERE contains(contenttitle, 'ado and net');   
  24.   
  25. SELECT *    
  26. FROM Contents   
  27. WHERE FREETEXT(contenttitle, 'ado  GUID');   
  28.   
  29. SELECT *    
  30. FROM Contents   
  31. WHERE CONTAINS(contenttitle, ' "ado*"');  


Si è verificato un errore imprevisto. Ricarica

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.