In Part 1 of Semantic Search Implementation that I published yesterday, I wrote about how to install and configure semantic search in SQL Server 2012. Today in Part 2, we will learn how to implement semantic search and will demonstrate how beneficial it is.
Prerequisite :
Given below are the two articles that you should read to have clear understanding about Semantic Search Implementation.
Lets Implement it step by step.
Step 1: Create database
USE master GO CREATE DATABASE [SampleDB] ON PRIMARY ( NAME = N'SampleDB', FILENAME = N'C:\DATA\SampleDB.mdf' ), FILEGROUP SampleFileGroup CONTAINS FILESTREAM (NAME = SampleFileTableFS, FILENAME='C:\Data\SampleFileTable' ) LOG ON ( NAME = N'SampleDB_log', FILENAME = N'C:\DATA\SampleDB_log.ldf' ) WITH FILESTREAM ( NON_TRANSACTED_ACCESS = FULL, DIRECTORY_NAME = N'SampleFileTableDB' ) GO
Step 2: Create FileTable
USE SampleDB GO CREATE TABLE CVBank AS FileTable WITH ( FileTable_Directory = 'CVFileTable_Dir' ); GO
Step 3: Populate data into FileTable
In this step, we will insert few Cvs in the file table.
USE SampleDB GO INSERT INTO [dbo].[CVBank] ([name],[file_stream]) SELECT'Muhammad Imran -CV.doc', * FROM OPENROWSET ( BULK N'C:\Cv\Muhammad Imran -CV.doc', SINGLE_BLOB ) AS FileData GO INSERT INTO [dbo].[CVBank] ([name],[file_stream]) SELECT 'Salman Tahir -CV.doc', * FROM OPENROWSET ( BULK N'C:\Cv\Salman Tahir -CV.doc', SINGLE_BLOB ) AS FileData GO INSERT INTO [dbo].[CVBank] ([name],[file_stream]) SELECT 'Syed Kamran Ali -CV.doc', * FROM OPENROWSET ( BULK N'C:\Cv\Syed Kamran Ali -CV.doc', SINGLE_BLOB ) AS FileData GO
Step 4: Create full text search on FileTable
Right click on the file table point to full-Text index then select Define Full-Text Index… Further details to create Full Text Index is available here
Now, we are prepared to use semantic search. Lets create few examples.
Example 1: Search Sharepoint Developer CVs
As I mentioned above that, I populated some CVs in the file table, now it is time to search Cvs with certain criteria using semantic search.
In this example, I will search candidates having knowledge of sharepoint.
USE SampleDB GO SELECT D.name ,KEYP_TBL.score ,KEYP_TBL.Keyphrase FROM dbo.CVBank D INNER JOIN SEMANTICKEYPHRASETABLE ( dbo.CVBank,(name,file_stream) ) AS KEYP_TBL ON D.path_locator = KEYP_TBL.document_key WHERE KEYP_TBL.keyphrase like '%sharepoint%' ORDER BY KEYP_TBL.score DESC --OUTPUT
Example 2: Search SQL Developer CVs
In this example, I will search candidates having knowledge of SQL.
USE SampleDB GO SELECT D.name ,KEYP_TBL.score ,KEYP_TBL.Keyphrase FROM dbo.CVBank D INNER JOIN SEMANTICKEYPHRASETABLE ( dbo.CVBank,(name,file_stream) ) AS KEYP_TBL ON D.path_locator = KEYP_TBL.document_key WHERE KEYP_TBL.keyphrase like '%sql%' ORDER BY KEYP_TBL.score DESC --OUTPUT
Conclusion :
Semantic Search is very handy if you need to develop some solution on the basis of unstructured document. Shall post another nice feature of semantic search in my upcoming post.
awesome article imran 🙂
Reblogged this on Sutoprise Avenue, A SutoCom Source.
[…] in SQL Server 2012) and tried to create a full text index. Most likely this error is related to semantic search (A new type of search concept came in SQL Server 2012). Let me explain this error in detail […]
[…] in SQL Server 2012) and tried to create a full text index. Most likely this error is related to semantic search (a new type of search concept came in SQL Server 2012). Let me explain this error in detail […]
nice article. Thanx a lot 🙂
And I would like to know, this can be use for search multiple keyphrases?