Solved

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

Posted on 2011-09-14
3
1,031 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
  • 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 500 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

803 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