Author |
Topic |
alexellice
Starting Member
13 Posts |
Posted - 2012-04-04 : 13:04:41
|
Hi all..I'm building a new website that will have many thousands of records in a database. The problem I have is that I'm going to need to be able to use multiple search queries at once.. Example:John Blackwell is in the night clubI will remove "is, in and the" but I still need to find hits with John, John Blackwell, night, club and nightclub.The webhotel does not support full text search either :-( So any suggestions here pls ????(The search would be carried out in the description field only.. so no need for multiple tables or databases.)Forgot to say that I'm using MS sql server 2008, asp.net 4 and c# |
|
X002548
Not Just a Number
15586 Posts |
Posted - 2012-04-04 : 13:19:09
|
Well it's really justJohn, Blackwell, night, club and nightclubRightDo you mean you need top parse a string a look for thos values?I would create a table udf that parses the string and would join to with a likeSELECT Parameter, yourDescription FROM yourTableINNER JOIN dbo.udf_TableON yourDescription LIKE '%' + Parameter + '%'CREATE FUNCTION [dbo].[udf_Table](@ParmList varchar(8000), @Delim varchar(20))RETURNS @table TABLE (Parameter varchar(255))AS /* SELECT * FROM dbo.udf_Table( 'a|~|b|~|c', '|~|')*/BEGIN DECLARE @x int, @Parameter varchar(255) WHILE CHARINDEX(@Delim, @ParmList)-1 > 0 BEGIN INSERT INTO @table(Parameter) SELECT SUBSTRING(@ParmList,1,CHARINDEX(@Delim, @ParmList)-1) SELECT @ParmList = SUBSTRING(@ParmList,CHARINDEX(@Delim, @ParmList)+LEN(@Delim), LEN(@ParmList)-CHARINDEX(@Delim,@ParmList)) END INSERT INTO @table(Parameter) SELECT @ParmList RETURNEND Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxWant to help yourself?http://msdn.microsoft.com/en-us/library/ms130214.aspxhttp://weblogs.sqlteam.com/brettk/http://brettkaiser.blogspot.com/ |
 |
|
alexellice
Starting Member
13 Posts |
Posted - 2012-04-04 : 15:14:32
|
right.. thankyou for such a quick response... I'n not good with sql. But I'll give this a go..I ran (installed) the function you wrote but how to I access it now?example:From my c# I will send a query to the Db... Something like :SELECT * FROM Gallery WHERE imgDescr LIKE @_searchwhat do I do with what you gave me? |
 |
|
X002548
Not Just a Number
15586 Posts |
|
alexellice
Starting Member
13 Posts |
Posted - 2012-04-04 : 16:41:28
|
ok... I ran a test.. but its not working right?this is my test queryDECLARE @_search varchar;set @_search = 'janni'SELECT Parameter, imgDescr FROM LH_GalleryINNER JOIN dbo.udf_Table(@_search,' ')ON imgDescr LIKE '%' + Parameter + '%'it only selects (or searches) for the first letter (j) |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
X002548
Not Just a Number
15586 Posts |
Posted - 2012-04-04 : 19:44:28
|
quote: Originally posted by alexellice ok... I ran a test.. but its not working right?this is my test queryDECLARE @_search varchar;set @_search = 'janni'SELECT Parameter, imgDescr FROM LH_GalleryINNER JOIN dbo.udf_Table(@_search,' ')ON imgDescr LIKE '%' + Parameter + '%'it only selects (or searches) for the first letter (j)
Dude ( or Dudette), that's only because your declare is for a 1 byte valueDo thisDECLARE @_search varchar(255);and Try set @_search = 'janni is a chick e'Should give you matches on%janni% -- any janni matches%is% -- any matches for is, for example this%a% -- anything with an a in it$chick% -- anything matching chick%e% -- anything with an eBrett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxWant to help yourself?http://msdn.microsoft.com/en-us/library/ms130214.aspxhttp://weblogs.sqlteam.com/brettk/http://brettkaiser.blogspot.com/ |
 |
|
X002548
Not Just a Number
15586 Posts |
|
alexellice
Starting Member
13 Posts |
Posted - 2012-04-05 : 02:33:12
|
ok... GREAT... that really helped (I did say that I'm not good at SQL!)I used thisDECLARE @_search varchar(255);set @_search = 'rasmus caroline'SELECT Parameter, imgDescr FROM LH_GalleryINNER JOIN dbo.udf_Table(@_search,' ')ON imgDescr LIKE '%' + Parameter + '%'Problem is that it looks for "rasmus" and then only "carolin" (missing the last letter).. if I try any suggests why?actually, after further testing.. If I write "Sofie Rasmus og Mille" it will search for "Sofie" and "rasmus og mill" (missing last letter + not seperating words)I'm really happy that we're getting somewhere with this now... and really appreciate all your help.I should also mention that I want to return the results, when it works correctly as a table with all the fields included, not just the ones searched in |
 |
|
Jeff Moden
Aged Yak Warrior
652 Posts |
Posted - 2012-04-08 : 18:27:27
|
quote: Originally posted by X002548
quote: Originally posted by visakh16 here's another versionhttp://visakhm.blogspot.com/2010/02/parsing-delimited-string.html------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
I wonder how much faster that isBrett
It's likely not that much faster because it still uses a WHILE loop. Check out the following article for performance curves and a seriously improved method for splitting strings.http://www.sqlservercentral.com/articles/Tally+Table/72993/--Jeff Moden |
 |
|
|