Skip to content

Instantly share code, notes, and snippets.

@bozhink
Created July 5, 2017 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bozhink/bed02ec68a41e1aaf21bafb6bf061851 to your computer and use it in GitHub Desktop.
Save bozhink/bed02ec68a41e1aaf21bafb6bf061851 to your computer and use it in GitHub Desktop.
FullTest search in tSQL
-- https://www.simple-talk.com/sql/learn-sql-server/understanding-full-text-indexing-in-sql-server/
IF OBJECT_ID (N'ProductDocs', N'U') IS NOT NULL  
DROP TABLE ProductDocs  
GO
CREATE TABLE ProductDocs (  
  DocID INT NOT NULL IDENTITY,  
  DocTitle NVARCHAR(50) NOT NULL,  
  DocFilename NVARCHAR(400) NOT NULL,  
  FileExtension NVARCHAR(8) NOT NULL,  
  DocSummary NVARCHAR(MAX) NULL,  
  DocContent VARBINARY(MAX) NULL,  
  CONSTRAINT [PK_ProductDocs_DocID] PRIMARY KEY CLUSTERED (DocID ASC)  
)  
GO
--INSERT INTO ProductDocs  
--(DocTitle, DocFilename, FileExtension, DocSummary, DocContent)  
--SELECT Title, FileName, FileExtension, DocumentSummary, Document  
--FROM Production.Document  
--GO
CREATE FULLTEXT CATALOG ProductFTS
WITH ACCENT_SENSITIVITY = OFF
CREATE FULLTEXT INDEX ON ProductDocs  
(DocSummary, DocContent TYPE COLUMN FileExtension LANGUAGE 1033)  
KEY INDEX PK_ProductDocs_DocID  
ON ProductFTS  
WITH STOPLIST = SYSTEM
CREATE FULLTEXT STOPLIST ProductSL
FROM SYSTEM STOPLIST;
SELECT stoplist_id, name FROM sys.fulltext_stoplists
SELECT stopword FROM sys.fulltext_stopwords  
WHERE stoplist_id = 5 AND language_id = 1033
ALTER FULLTEXT STOPLIST ProductSL  
ADD 'nuts' LANGUAGE 1033;
SELECT special_term, display_term  
FROM sys.dm_fts_parser  
  (' "testing for fruit and nuts, any type of nut" ', 1033, 5, 0)
ALTER FULLTEXT INDEX ON ProductDocs  
SET STOPLIST ProductSL
SELECT * FROM sys.fulltext_languages ORDER BY lcid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment