Hi
I am trying to find exact matches for keywords in resumes using fulltext queries.
I am using following queries. Is it possible to find which keyword(searchterm) matched the search ?
I am looking for an optimized way of doing this.
TIA
Expected Result
=====================
LastName KeywordMatched
Smith New York
Doe Dallas
Henry Chicago
GO
EXEC sp_fulltext_database enable
GO
SET NOCOUNT ON
CREATE TABLE SearchTerm (ID int Identity(1,1),Term nvarchar(100))
CREATE TABLE ApplicantResume(ID int Identity(1,1) constraint PK_ApplicantResume primary key (ID) NOT NULL,FirstName varchar(25), LastName varchar(25),ResumeText varchar(Max))
CREATE FULLTEXT CATALOG MySearchCatalog WITH ACCENT_SENSITIVITY = ON AUTHORIZATION [dbo]
CREATE FULLTEXT INDEX ON [dbo]. ApplicantResume (ResumeText) KEY INDEX PK_ApplicantResume ON MySearchCatalog WITH CHANGE_TRACKING AUTO
insert into ApplicantResume VALUES('N','Smith','I live in New York')
insert into ApplicantResume VALUES('D','Doe','I live in Dallas and work in Chicago')
insert into ApplicantResume VALUES('C','Henry','I live in Chicago')
INSERT SearchTerm VALUES ('New York')
INSERT SearchTerm VALUES ('Dallas')
INSERT SearchTerm VALUES ('Chicago')
--It takes sometime to populate fulltext index. Run this query again.
SELECT FT.[Rank], FirstName,LastName FROM ApplicantResume R LEFT OUTER JOIN
CONTAINSTABLE(ApplicantResume,ResumeText,'"New York" OR "Dallas" OR "Chicago" OR "Los Angeles" ') FT ON R.ID = FT.[KEY]