Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do i make full text search search for partial words and individual words

Posted on 2011-09-14
3
Medium Priority
?
1,279 Views
Last Modified: 2012-08-13
I’m currently using full text search on 3 fields in my database, e.g. name, sku, details
However were having difficulty getting the search to work as expected e.g.
1)  We’re searching for whole lines and not each word as say google for example e.g. Lets say we have a detail of “the cat sat on the mat” then searching for “cat"  or “cat sat” will work but searching the “cat mat” won’t, so my question is, is there a way to have fts work smarter and break down the contents.
2)  partial word search don’t work as per the example above if I search for “ma” nothing will get returned but if I search for “mat” it will, is there a way around this?

My current stored procedure can be found below, and can any replies ideally include how it should be amended please

Thanks in advance
Webbo

DECLARE @FORMSOF as varchar(1000)
DECLARE @Phrase as varchar(1000)
SET @FORMSOF = 'FORMSOF (INFLECTIONAL, "' + @SearchText + '")'
SET @PHRASE =  '"' + @SearchText  + '"';
WITH Products AS
(
	SELECT ID, [Name], Sku, Origin, Price, ROW_NUMBER() over (ORDER BY ID) AS 'RowNumber'

	FROM mytable P
	WHERE 
		P.Active = 1
		and
		(
			CONTAINS(Name, @FORMSOF) --Search for forms of input text in product name
			OR CONTAINS(Detail, @FORMSOF) -- Search for forms of input text in product description
			OR CONTAINS(Origin, @PHRASE) -- Search for input text in Origin field
			OR SKU Like '%' + @SearchText + '%' -- Search for input text in Sku field
		)
)

SELECT * FROM Products

Open in new window

0
Comment
Question by:Webbo_1980
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 22

Expert Comment

by:pivar
ID: 36534990
Hi,

How do you format @SearchText?

You need to have an op between each word, like

' "cat" AND "mat" '

With partial search you 'll need

' "cat" AND "ma*" '

/peter

0
 

Author Comment

by:Webbo_1980
ID: 36535082
at the minute the @searchText come in as 'the cat sat on the mat'

Is there a way in sql to split this to say something like replace every space with "* AND " ?

so
'the cat sat on the mat'

would then be
'the* AND cat* AND sat* AND on* AND the* AND mat'

and if so is this the best way to do it do you think?
0
 
LVL 22

Accepted Solution

by:
pivar earned 2000 total points
ID: 36535149
I would recommend you to build the searchtext where you interact with the user, that is, in your gui.

But you should be able to to something like

@SearchText = '"' + REPLACE(@SearchText, ' ', '*" AND "') + '*"'

This expect the text to be formatted with only one space between the words, and no other spaces.
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

715 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