Solved

Using FREETEXT SEARCH to do Partial Match

Posted on 2007-11-14
8
810 Views
Last Modified: 2010-08-05
Hi there I am using FREETEXTSEARCH, Here are the clauses in question.

AND
((@Search is null or FREETEXT(DescriptionSelConcept, @Search) )
or
(@Search is null or FREETEXT(LessonsLearnt, @Search) )
or
(@Search is null or FREETEXT(ProjectTitle, @Search) )
or
(@Search is null or FREETEXT(BriefDescriptionScope, @Search) )
or
(@Search is null or FREETEXT(JobNumber, @Search) ))

At the moment these clauses only do exact match for instance if im searching for "blackhorse" in the ProjectTitle I MUST type in Blackhorse for the result to appear, I would like to be able to type "black" as well for it to appear, does anyone know how I can modify this to do this?
0
Comment
Question by:MayoorPatel
  • 3
  • 3
  • 2
8 Comments
 
LVL 42

Expert Comment

by:EugeneZ
Comment Utility
try to use CONTAINS instead of FREETEXT:
http://msdn2.microsoft.com/en-us/library/aa258227(SQL.80).aspx
----------------------------------------
Example:

USE Northwind
GO
SELECT ProductName
FROM Products
WHERE CONTAINS(ProductName, ' "choc*" ')
GO
0
 
LVL 1

Author Comment

by:MayoorPatel
Comment Utility
Nope just tried this

AND
((@Search is null or CONTAINS(DescriptionSelConcept, @Search) )
or
(@Search is null or CONTAINS(LessonsLearnt, @Search) )
or
(@Search is null or CONTAINS(ProjectTitle, @Search) )
or
(@Search is null or CONTAINS(BriefDescriptionScope, @Search) )
or

and its still not returning the record on partial match
0
 
LVL 42

Expert Comment

by:EugeneZ
Comment Utility
try rtrim(@search) + '*'
0
 
LVL 1

Author Comment

by:MayoorPatel
Comment Utility
AND
((@Search is null or CONTAINS(DescriptionSelConcept, rtrim(@search) + '*') )
or
(@Search is null or CONTAINS(LessonsLearnt, rtrim(@search) + '*') )
or
(@Search is null or CONTAINS(ProjectTitle, rtrim(@search) + '*') )
or
(@Search is null or CONTAINS(BriefDescriptionScope, rtrim(@search) + '*') )
or


gives a syntax error in the SQL


0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 42

Expert Comment

by:EugeneZ
Comment Utility
try

--
AND
((@Search is null or CONTAINS(DescriptionSelConcept,'"'+@search+'*"') )
or
(@Search is null or CONTAINS(LessonsLearnt, '"'+@search+'*"') )
or
(@Search is null or CONTAINS(ProjectTitle, '"'+@search+'*"' )
or
(@Search is null or CONTAINS(BriefDescriptionScope,'"'+@search+'*"') )
or

----------
see working example:


USE AdventureWorks;
GO
declare @search varchar(50)
set @search=' Chain '
set @search='"'+@search+'*"'
SELECT Name
FROM Production.Product
WHERE CONTAINS(Name, @search);
GO
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 500 total points
Comment Utility
You might find it a little more efficient, if you set the @Search before and use * instead of repeating all the columns in endless OR clauses, as in:

SET @Search = '"' + @Search + '*"'

...

AND
@Search Is Null Or CONTAINS(*, @Search)

0
 
LVL 1

Author Comment

by:MayoorPatel
Comment Utility
aceperkins - Yes that would be correct IF I had wanted to search every column in the table as I only need to search 4 of them the way I have done it is correct.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
Comment Utility
No problem.  On a different note, please attend to all your abandoned questions:
1 10/19/2007 500 Converting a Dynamic versio... Open ASP
2 10/08/2007 500 Building A Search Query Open MS SQL Server ...
3 09/14/2007 500 How to Search 2 Colums in a... Open MS SQL Server
4 07/04/2007 500 UNION with DYNAMIC ORDER BY... Open Databases ...
5 07/04/2007 500 Filtering a Datalist Orderi... Open ASP.Net Programm...
6 06/25/2007 500 Overlapping Rendering of El... Open Firefox ...
7 06/22/2007 500 Object reference not set to... Open ASP.Net Programm... ...
8 04/04/2007 500 Group By Clause Problem wit... Open SQL Server 2005 ...
9 03/27/2007 500 How to Avoid Divide by Zero... Open MS SQL Server
10 03/26/2007 500 Calculated Column to calcul... Open SQL Server 2005 ...

Thanks.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now