SlideShare a Scribd company logo
DOCUMENTATION ON SEMANTIC SEARCH
A basic idea of semantic search can be obtained by going through the following link.
http://wiki.hsr.ch/Datenbanken/files/Semantic_Search_In_MS_SQL_2012_Rico_Suter.pdf
1.INSTALLATION OF SEMANTICS IN SQL SERVER
1.1 Installation First we have to install the Microsoft SQL Server 2012 with semantic search
capabilities. The setup needs three steps:
1. Installing the server with semantic search feature
2. Install additional filter packs
3. Install a Semantic Language Database
The details about the installation are also mentioned in the pdf link given above.
2. SEMANTIC SEARCHING
For a semantic to work on any table, say ​CM.APPLICATION_GROUP_MF​,
we have to create two things,
1. Catalog for a table
2. Fulltext Index for a table
2.1 CATALOGUE CREATION
The syntax for making the catalog is as follows:
CREATE​​FULLTEXT​​CATALOG​​<catalogname>​​WITH​​ACCENT_SENSITIVITY​​=​​ON​;
​Go
An example is given below:
--createcatalogforCM.APPLICATION_GROUP_MF
CREATE​​FULLTEXT​​CATALOG​​Application_groupCatalog​​WITH​​ACCENT_SENSITIVITY​​=​​ON​;
​Go
2.1 FULLTEXT INDEX CREATION
The syntax for creating a Fulltext Index is as follows:
CREATE​​FULLTEXT​​INDEX​​ON​​<TableName>​​(
[ColumnName]​​LANGUAGE​1033​Statistical_Semantics​,
[ColumnName]​​LANGUAGE​1033​Statistical_Semantics​,
.
.
.
[ColumnName]​LANGUAGE​1033​Statistical_Semantics
)
KEY​​INDEX​<​PK_TableName>
ON​​<catalog_created_previously>
WITH​​STOPLIST​​=​​SYSTEM
Go
An Example has been given below:
--createFULLTEXTINDEXonCM.APPLICATION_GROUP_MF
​CREATE​​FULLTEXT​​INDEX​​ON​​CM​.​APPLICATION_GROUP_MF​​(
[HARD_CODE]​​LANGUAGE​1033​Statistical_Semantics​,
[NAME]​​LANGUAGE​1033​Statistical_Semantics​,
[UPDATED_BY]​​LANGUAGE​1033​Statistical_Semantics
)
KEY​​INDEX​​PK_APPLICATION_GROUP_MF
ON​​Application_groupCatalog
WITH​​STOPLIST​​=​​SYSTEM
Go
Now as we have created both index and catalog for a given table, we can apply semantics to that as
follows :
DECLARE​​@SearchTerm​​AS​​NVARCHAR​(​max​);
Set​​@SearchTerm​=​'<whatyouwanttosearch>'​;
DECLARE​​@cmd​​AS​​NVARCHAR​(​max​)
DECLARE​​@tmpSearch​​NVARCHAR​(​500​)
SELECT​​@tmpSearch​​=​​REPLACE​(​@SearchTerm​,​''​,​''','''​)
SET​​@cmd​​=​​N'SELECT*FROM<​TableName>​INNERJOIN
semantickeyphrasetable(<​TableName>​,*)
on<​primarykey_of_the_table>​=document_keyWHEREkeyphraseIN
('''​+​@tmpSearch​+​''')ORDERBYscoreDESC'
print​​@cmd
EXEC​(​@cmd​)
An example has been given below :
DECLARE​​@SearchTerm​​AS​​NVARCHAR​(​max​);
Set​​@SearchTerm​=​'WHATARETHEDETAILSABOUTSHIPMATE'​;
DECLARE​​@cmd​​AS​​NVARCHAR​(​max​)
DECLARE​​@tmpSearch​​NVARCHAR​(​500​)
SELECT​​@tmpSearch​​=​​REPLACE​(​@SearchTerm​,​''​,​''','''​)
SET​​@cmd​​=​​N'SELECT*FROMCM.APPLICATION_GROUP_MFINNERJOIN
semantickeyphrasetable(CM.APPLICATION_GROUP_MF,*)
onID=document_keyWHEREkeyphraseIN('''​+​@tmpSearch​+​''')ORDERBYscoreDESC'
print​​@cmd
EXEC​(​@cmd​)
Now, if you want to apply semantics to a combination of tables, you can use inner join of tables.
Eg,
​SET​​@cmd​​=​​N'SELECTdistincta.SUR_NAME,a.FIRST_NAME,a.MIDDLE_NAME,c.APPRAISAL_SCORE
FROM CM.PERSONNEL_MFasa
INNERJOINsemantickeyphrasetable(CM.PERSONNEL_MF,*)assona.id=document_key
INNERJOINFD.TEMPLATE_DATA_HDasconc.EMP_ID=a.id
InnerJoinsemantickeyphrasetable(FD.TEMPLATE_DATA_HD,*)asqonc.ID=q.document_key
WHEREq.keyphraseIN('''​+​@tmpSearch​+​''')ors.keyphraseIN('''​+​@tmpSearch​+​''')'
Here, appraisal_score is in ​FD.TEMPLATE_DATA_HD​table and and the rest of the selected columns are
from ​CM.PERSONNEL_MF​table. So, here we are applying semantics to the combination of both the
tables.
Semantics without the required BUSSINESS LOGIC is useless. So, we shall now learn how to include
BUSSINESS LOGIC to the semantics.
Now, lets consider a table, Data1
Now, we need to find the most intelligent students from this table. So, here I give the condition as
best student = APPRAISAL_SCORE >9
Similarly, a bad student is a student whose APPRAISAL_SCORE<5
So, using semantics , we can give intelligence to our program.
For doing so, we have to give ‘Qualifier Tables’.
So, my Qualifier table in this case is ​Qualifier_Promotion
Now, I shall share the code here:
USE​​SHIPMATE1704_4SBNT
GO
/******Object: StoredProcedure[dbo].[shipmate_Search] ScriptDate:6/5/2015
12:04:49AM******/
SET​​ANSI_NULLS​​ON
GO
SET​​QUOTED_IDENTIFIER​​ON
GO
--toexecutetheprocedure
--execshipmate_Search'whoisbothgoodandreliableofallfromData1'
ALTER​​PROCEDURE​​[dbo]​.​[shipmate_Search]
​(
​@SearchTerm​​NVARCHAR​(​500​)
)
​AS
​BEGIN
​DECLARE​​@cmd​​AS​​NVARCHAR​(​max​)
DECLARE​​@columnname​​AS​​NVARCHAR​(​max​)
DECLARE​​@tmpSearch​​NVARCHAR​(​500​)
DECLARE​​@wherequery​​NVARCHAR​(​Max​)​​=​​NULL
Declare​​@orderbyquery​​NVARCHAR​(​MAX​)=NULL
Declare​​@SQLQUERY​​NVARCHAR​(​MAX​)
DECLARE​​@cmd2​​AS​​NVARCHAR​(​max​)
SELECT​​@tmpSearch​​=​​REPLACE​(​@SearchTerm​,​''​,​''','''​)
---Qualifierlisttabledatafetch---
​SET​​@cmd2​​=​​N'SELECT*into##tempTable2FROMQualifier_PromotionWHERE
WordIN('''​+​@tmpSearch​+​''')orSynonymsIN('''​+​@tmpSearch​+​''')'
​print​​@cmd2
​EXEC​(​@cmd2​)
​select​​*​​into​​#temp​​from​​##tempTable2
​drop​​table​​##tempTable2
declare​​@TableID​​int
--select*fromQualifier_Promotion
while​​exists​​(​select​​*​​from​​#temp​)
begin
​Declare​​@rowtype​​nvarchar​(​max​)
​Declare​​@rowcondn​​nvarchar​(​max​)
​select​​@TableID​​=​​(​select​​top​1​ID
​from​​#temp
​order​​by​​ID​​asc​)
---Createconditionforfilteringandsortingthequery------
select​​@rowtype​=​type​​from​​#temp​​as​​a​​where​​ID​=​@TableID
select @rowcondn​=​​LogicalExpression​​from​​#temp​​as​​a​​where
ID​=​@TableID
if​(​@rowtype​=​'Filter'​)
Begin
if​(​@wherequery​​IS​​NULL)
begin
​select​​@wherequery​​=​​@rowcondn
end
else
Begin
​SELECT​​@wherequery​=​@wherequery​​+​'and'​+​​@rowcondn
​end
end
​else
​Begin
​if​(​@orderbyquery​​IS​​NULL)
begin
​select​​@orderbyquery​​=​​@rowcondn
end
else
Begin
SELECT​​@orderbyquery​=​@orderbyquery​​+​'and'​+​​@rowcondn
end
​end
-------------------------------------------------------------
​delete​​#temp
​where​​ID​​=​​@TableID
end
if​(​@wherequery​​IS​​NOT​​NULL)
​begin
​select​​@wherequery​=​'where'​+​@wherequery
​end
else
​begin
​set​​@wherequery​=​''
​end
if​(​@orderbyquery​​IS​​NOT​​NULL)
​begin
​select​​@orderbyquery​=​'orderby'​+​@orderbyquery
​end
​else
​begin
​set​​@orderbyquery​=​''
​end
-------------------------------------
----Fetchdatafromsampletable----
--IF(ISNULL(@columnname,'')='')
SET​​@columnname​​=​​'*'
​--SET@cmd=N'SELECTa.*into##localtableFROMDataasaInnerJoin
semantickeyphrasetable(Data,'+@ColumnName+')
--assona.id=s.document_key WHEREs.keyphraseIN
('''+@tmpSearch+''')'
Select​​*​​from​​Data1
SET​​@cmd​​=​​N'SELECTa.*into##localtableFROMData1asaInnerJoin
semantickeyphrasetable(Data1,'​+​@ColumnName​+​')
assona.id=s.document_key'
print​​@cmd
​EXEC​(​@cmd​)
select​​*​​into​​#localtemptable1​​from​​##localtable
drop​​table​​##localtable
SET​​@SQLQuery​​=​​'SELECTDistinctID,Name,APPRAISAL_SCOREFROM
#localtemptable1'​​+​@wherequery​+​''​+​​@orderbyquery
print​​@SQLQuery
​EXEC​(​@SQLQuery​)
​END
​update​​Data1​​set​​APPRAISAL_SCORE​=​8.2​WHERE​​ID​=​3
--execshipmate_Search'abadstudent'
Please note that there is no need for applying semantics to the Qualifier table.
We are able to observe that the following query got replaced by
'SELECTDistinctID,Name,APPRAISAL_SCOREFROM#localtemptable1'​​+​@wherequery​+​''​+
@orderbyquery
I hope I have given all relevant data.
Please note that, the Tablename should be the tablename in which the contents you want to apply
semantics is stored.
Documented By,
Aiswarya Vinayachandran 6/6/2015
Amrita Vishwa Vidyapeetham 2:26 P.M
Coimbatore

More Related Content

What's hot

Payilagam oracle sql & plsql training syllabus
Payilagam oracle sql & plsql training syllabusPayilagam oracle sql & plsql training syllabus
Payilagam oracle sql & plsql training syllabus
Payilagam Software Training institute
 
Validation type 'special' in value sets
Validation type 'special' in value setsValidation type 'special' in value sets
Validation type 'special' in value sets
Feras Ahmad
 
If Function In Excel
If Function In ExcelIf Function In Excel
If Function In Excel
dinesh takyar
 
Oaf development-guide
Oaf development-guideOaf development-guide
Oaf development-guide
俊 朱
 
Bi
BiBi
Oracle Forms: Messages
Oracle Forms: MessagesOracle Forms: Messages
Oracle Forms: Messages
Sekhar Byna
 
My sql udf,views
My sql udf,viewsMy sql udf,views
Oa Framework Tutorial
Oa Framework TutorialOa Framework Tutorial
Oa Framework Tutorial
nolimit797
 

What's hot (8)

Payilagam oracle sql & plsql training syllabus
Payilagam oracle sql & plsql training syllabusPayilagam oracle sql & plsql training syllabus
Payilagam oracle sql & plsql training syllabus
 
Validation type 'special' in value sets
Validation type 'special' in value setsValidation type 'special' in value sets
Validation type 'special' in value sets
 
If Function In Excel
If Function In ExcelIf Function In Excel
If Function In Excel
 
Oaf development-guide
Oaf development-guideOaf development-guide
Oaf development-guide
 
Bi
BiBi
Bi
 
Oracle Forms: Messages
Oracle Forms: MessagesOracle Forms: Messages
Oracle Forms: Messages
 
My sql udf,views
My sql udf,viewsMy sql udf,views
My sql udf,views
 
Oa Framework Tutorial
Oa Framework TutorialOa Framework Tutorial
Oa Framework Tutorial
 

Similar to semantics_documentationsbn

127556030 bisp-informatica-question-collections
127556030 bisp-informatica-question-collections127556030 bisp-informatica-question-collections
127556030 bisp-informatica-question-collections
Amit Sharma
 
SQL Tunning
SQL TunningSQL Tunning
SQL Tunning
Dhananjay Goel
 
Admin Guiding Query Plans
Admin Guiding Query PlansAdmin Guiding Query Plans
Admin Guiding Query Plans
rsnarayanan
 
Sql interview question part 8
Sql interview question part 8Sql interview question part 8
Sql interview question part 8
kaashiv1
 
Ebook8
Ebook8Ebook8
Ebook8
kaashiv1
 
01 surya bpc_script_ppt
01 surya bpc_script_ppt01 surya bpc_script_ppt
01 surya bpc_script_ppt
Surya Padhi
 
Waiting too long for Excel's VLOOKUP? Use SQLite for simple data analysis!
Waiting too long for Excel's VLOOKUP? Use SQLite for simple data analysis!Waiting too long for Excel's VLOOKUP? Use SQLite for simple data analysis!
Waiting too long for Excel's VLOOKUP? Use SQLite for simple data analysis!
Amanda Lam
 
1 z0 062 - oracle certification
1 z0 062 - oracle certification1 z0 062 - oracle certification
1 z0 062 - oracle certification
adam_jhon
 
Sql server 2012 tutorials writing transact-sql statements
Sql server 2012 tutorials   writing transact-sql statementsSql server 2012 tutorials   writing transact-sql statements
Sql server 2012 tutorials writing transact-sql statements
Steve Xu
 
Advance Sql Server Store procedure Presentation
Advance Sql Server Store procedure PresentationAdvance Sql Server Store procedure Presentation
Advance Sql Server Store procedure Presentation
Amin Uddin
 
Oracle HRMS Fast Formula
Oracle HRMS Fast FormulaOracle HRMS Fast Formula
Oracle HRMS Fast Formula
runjithrocking
 
Ebook11
Ebook11Ebook11
Ebook11
kaashiv1
 
Oracle Discoverer Reports via BSS
Oracle Discoverer Reports via BSSOracle Discoverer Reports via BSS
Oracle Discoverer Reports via BSS
Khalid Tariq
 
123448572 all-in-one-informatica
123448572 all-in-one-informatica123448572 all-in-one-informatica
123448572 all-in-one-informatica
homeworkping9
 
5 tsssisu sql_server_2012
5 tsssisu sql_server_20125 tsssisu sql_server_2012
5 tsssisu sql_server_2012
Steve Xu
 
Ebook9
Ebook9Ebook9
Ebook9
kaashiv1
 
Sql interview question part 9
Sql interview question part 9Sql interview question part 9
Sql interview question part 9
kaashiv1
 
Sql interview-question-part-9
Sql interview-question-part-9Sql interview-question-part-9
Sql interview-question-part-9
kaashiv1
 
Ebook9
Ebook9Ebook9
Ebook9
kaashiv1
 
1 z0 060 - oracle certification
1 z0 060 - oracle certification1 z0 060 - oracle certification
1 z0 060 - oracle certification
adam_jhon
 

Similar to semantics_documentationsbn (20)

127556030 bisp-informatica-question-collections
127556030 bisp-informatica-question-collections127556030 bisp-informatica-question-collections
127556030 bisp-informatica-question-collections
 
SQL Tunning
SQL TunningSQL Tunning
SQL Tunning
 
Admin Guiding Query Plans
Admin Guiding Query PlansAdmin Guiding Query Plans
Admin Guiding Query Plans
 
Sql interview question part 8
Sql interview question part 8Sql interview question part 8
Sql interview question part 8
 
Ebook8
Ebook8Ebook8
Ebook8
 
01 surya bpc_script_ppt
01 surya bpc_script_ppt01 surya bpc_script_ppt
01 surya bpc_script_ppt
 
Waiting too long for Excel's VLOOKUP? Use SQLite for simple data analysis!
Waiting too long for Excel's VLOOKUP? Use SQLite for simple data analysis!Waiting too long for Excel's VLOOKUP? Use SQLite for simple data analysis!
Waiting too long for Excel's VLOOKUP? Use SQLite for simple data analysis!
 
1 z0 062 - oracle certification
1 z0 062 - oracle certification1 z0 062 - oracle certification
1 z0 062 - oracle certification
 
Sql server 2012 tutorials writing transact-sql statements
Sql server 2012 tutorials   writing transact-sql statementsSql server 2012 tutorials   writing transact-sql statements
Sql server 2012 tutorials writing transact-sql statements
 
Advance Sql Server Store procedure Presentation
Advance Sql Server Store procedure PresentationAdvance Sql Server Store procedure Presentation
Advance Sql Server Store procedure Presentation
 
Oracle HRMS Fast Formula
Oracle HRMS Fast FormulaOracle HRMS Fast Formula
Oracle HRMS Fast Formula
 
Ebook11
Ebook11Ebook11
Ebook11
 
Oracle Discoverer Reports via BSS
Oracle Discoverer Reports via BSSOracle Discoverer Reports via BSS
Oracle Discoverer Reports via BSS
 
123448572 all-in-one-informatica
123448572 all-in-one-informatica123448572 all-in-one-informatica
123448572 all-in-one-informatica
 
5 tsssisu sql_server_2012
5 tsssisu sql_server_20125 tsssisu sql_server_2012
5 tsssisu sql_server_2012
 
Ebook9
Ebook9Ebook9
Ebook9
 
Sql interview question part 9
Sql interview question part 9Sql interview question part 9
Sql interview question part 9
 
Sql interview-question-part-9
Sql interview-question-part-9Sql interview-question-part-9
Sql interview-question-part-9
 
Ebook9
Ebook9Ebook9
Ebook9
 
1 z0 060 - oracle certification
1 z0 060 - oracle certification1 z0 060 - oracle certification
1 z0 060 - oracle certification
 

semantics_documentationsbn