Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
jmcbride
Starting Member
24 Posts |
Posted - 2003-07-24 : 15:13:51
|
| Hi, trying to setup a query that can take more that one word and search for them independantly. Then return the results ranked according to the relevancy of the words.Example:If I search for three words: Joe College SmithMy results could be:smith Joe CollegeJoe CollegeJoe SmithSmithCollegeJoeDo you see how they would be ranked by relevancy?Thanks!--------------------http://www.utsa.edu/(Joe) Joseph McBride |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2003-07-24 : 15:26:56
|
| I'm assuming you mean to search 1 column in a table, yes?Brett8-) |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2003-07-24 : 15:47:48
|
I don't know if this helps..but it finds the number of words in a string..maybe you can modify it..but I think you're going to have to get real creative..CREATE FUNCTION udf_WORDS (@str varchar(8000))RETURNS intASBEGIN DECLARE @Words INT, @Pos INT, @x Int SELECT @Words = 0, @Pos = 1, @x = -1 WHILE (@x <> 0) BEGIN SET @x = CHARINDEX(' ', @str, @Pos) SET @Pos = @x + 1 SET @Words = @Words + 1 END RETURN @WordsENDBrett8-) |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
jmcbride
Starting Member
24 Posts |
Posted - 2003-07-24 : 16:16:30
|
quote: I'm assuming you mean to search 1 column in a table, yes?Brett8-)
There are actually two columns in a table (first and last names).--------------------http://www.mejoe.com/(Joe) Joseph McBride |
 |
|
|
JimL
SQL Slinging Yak Ranger
1537 Posts |
Posted - 2003-07-24 : 17:12:30
|
| Three words against two fields, dbo.table1.fistname and dbo.table1.lastnameAm I missing something???Full text index = Slow D.B. shazbat!JimUsers <> Logic |
 |
|
|
jmcbride
Starting Member
24 Posts |
Posted - 2003-07-26 : 16:53:19
|
quote: Three words against two fields, dbo.table1.fistname and dbo.table1.lastnameAm I missing something???Full text index = Slow D.B. shazbat!JimUsers <> Logic
Thats right. Any ideas?--------------------http://www.mejoe.com/(Joe) Joseph McBride |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2003-07-26 : 17:40:00
|
| OK, here we go:First, the search terms must be put into a temp table, a regular table, or a table variable of some sort. there are articles and posts on how to do this from a comma-seperated string (CSV) -- do some searching.Let's assume you have gotten your search terms into a table variable @Words, with a column called "Word".Next, the table you are searching -- let's call it SearchTable, and you are looking in COlumn1 and/or Column2 for matches. I assume each row in SearchTable has a unique keyfield, let's call it ID.So, take a look:select ID, 1.0 * count(*) / (Select COUNT(*) FROM @Words) as MatchPctfromSearchTable ainner join@Words bona.Column1 LIKE '%' + b.Word + '%' ORb.Column2 LIKE '%' + b.Word + '%'group by IDorder by count(*) DESCthat will return the matching ID's, with what the matching percent is .... this might not be very efficient (the LIKE joins with the %'s will require table scans) but it should work.- Jeff |
 |
|
|
|
|
|
|
|