Go Back

Text Search

MS SQL Server

MS SQL Server has the capability to index text and to process binary data through filters based on a file-extension field.

CREATE TABLE knowledgebase (
  id INT IDENTITY(1, 1) NOT NULL,
  title VARCHAR(50) NOT NULL,
  body VARCHAR(MAX) NOT NULL,
  CONSTRAINT PK_knowledgebase PRIMARY KEY CLUSTERED(id)
);
GO

INSERT INTO knowledgebase(title, body) VALUES('How to setup DNS', 'Create AAAA and PTR records');
GO

-- The full-text catalog can be created using the GUI from the context menu of "Databases > MyDB > Storage > Full Text Catalog"
CREATE FULLTEXT CATALOG ftcat AS DEFAULT;
GO

-- The full-text index can be created using the GUI from the context menu of the table
CREATE FULLTEXT INDEX ON knowledgebase(title, body) KEY INDEX PK_knowledgebase;
GO

-- From the table's context menu, "Full-Text index > Start Full Population"

SELECT * FROM knowledgebase WHERE FREETEXT(body, 'altering');
GO
-- The FREETEXT() and CONTAINS() operators use the full-text index
  

When specifying the columns in the CREATE FULLTEXT INDEX statement, "TYPE COLUMN" is used to specify the column with the file extension (Eg. .pdf). The LANGUAGE is specified using the "lcid" column of sys.syslanguages or the "alias".

Go Back