Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 829
  • Last Modified:

Using FREETEXT SEARCH to do Partial Match

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
MayoorPatel
Asked:
MayoorPatel
  • 3
  • 3
  • 2
1 Solution
 
Eugene ZCommented:
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
 
MayoorPatelAuthor Commented:
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
 
Eugene ZCommented:
try rtrim(@search) + '*'
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
MayoorPatelAuthor Commented:
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
 
Eugene ZCommented:
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
 
Anthony PerkinsCommented:
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
 
MayoorPatelAuthor Commented:
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
 
Anthony PerkinsCommented:
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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now