Solved

Search Freetext Multiple Columns SQL2000

Posted on 2007-11-29
7
446 Views
Last Modified: 2008-02-01
I am trying to query multiple columns in multiple tables.   I need to weigh certain columns in the results.  My current code looks as follows:
"select Key_Tbl.[key], tblBlogThreads.BlogThreadNum,  tblBlogThreads.Body,tblBlogThreads.PublishDate, tblBlogThreads.Title, tblBlogThreads.Teaser, tblBlogThreads.MetaKeywords,  [rank] from freetexttable(tblBlogThreads, body, '" & tstr & "' ) AS Key_Tbl  INNER JOIN tblBlogThreads ON tblBlogThreads.BlogthreadID = Key_Tbl.[key] order by [rank] desc"

The problem is i need to search in columns tblBlogThreads.Title,  tblBlogThreads, Keywords, and tblBlogThreads.Body, and weigh them in that order.    
0
Comment
Question by:DidiahProd
  • 4
  • 3
7 Comments
 
LVL 25

Expert Comment

by:imitchie
ID: 20379581
select
Key_Tbl.[key], tblBlogThreads.BlogThreadNum,  
tblBlogThreads.Body,tblBlogThreads.PublishDate,
tblBlogThreads.Title,
tblBlogThreads.Teaser,
tblBlogThreads.MetaKeywords,  
[rank]
from
(select [key], rank + 2000 as rank from freetexttable(tblBlogThreads, title, '" & tstr & "' )
 union all
 select [key], rank + 1000 from freetexttable(tblBlogThreads, keywords, '" & tstr & "' )
 union all
 select [key], rank from freetexttable(tblBlogThreads, body, '" & tstr & "' )
) AS Key_Tbl
INNER JOIN tblBlogThreads ON tblBlogThreads.BlogthreadID = Key_Tbl.[key]
order by [rank] desc
0
 
LVL 25

Expert Comment

by:imitchie
ID: 20379590
The ranks returned are 1-1000, therefore match by title will have high rank, then keywords, then body.  I forgot to trim duplicates. this one fixes it

select
Key_Tbl.[key], tblBlogThreads.BlogThreadNum,  
tblBlogThreads.Body,tblBlogThreads.PublishDate,
tblBlogThreads.Title,
tblBlogThreads.Teaser,
tblBlogThreads.MetaKeywords,  
[rank]
from
(select [key], max(rank) as rank from
(select [key], rank + 2000 as rank from freetexttable(tblBlogThreads, title, '" & tstr & "' )
 union all
 select [key], rank + 1000 from freetexttable(tblBlogThreads, keywords, '" & tstr & "' )
 union all
 select [key], rank from freetexttable(tblBlogThreads, body, '" & tstr & "' )
) tbl1
group by [key]) AS Key_Tbl
INNER JOIN tblBlogThreads ON tblBlogThreads.BlogthreadID = Key_Tbl.[key]
order by [rank] desc
0
 

Author Comment

by:DidiahProd
ID: 20379703
Thanks!

these look good but there's a syntax error in there somewhere- getting error near a space, near a space and near a ).
Looking into it...
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 25

Expert Comment

by:imitchie
ID: 20379706
That was meant to include a start " and an end " to be assigned to a string from ASP.NET.  That's why there are two
" & tstr & "
bits in the middle

It does not run as is and will cause an error from Query Analyzer!
But I think you get the idea.

0
 

Author Comment

by:DidiahProd
ID: 20379752
yah thanks- it runs in the QA but won't run in sql- looking more into it.  i can't get it to go in an SP either
0
 

Author Comment

by:DidiahProd
ID: 20379939
How would this be represented as a stored procedure where tsq is the parameter (@tsq)

select 
Key_Tbl.[key], tblBlogThreads.BlogThreadNum,  
tblBlogThreads.Body,tblBlogThreads.PublishDate, 
tblBlogThreads.Title, 
tblBlogThreads.Teaser, 
tblBlogThreads.MetaKeywords,  
[rank] 
from
(select [key], max(rank) as rank from
(select [key], rank + 2000 as rank from freetexttable(tblBlogThreads, title, '" & tstr & "' )
 union all
 select [key], rank + 1000 from freetexttable(tblBlogThreads, keywords, '" & tstr & "' )
 union all
 select [key], rank from freetexttable(tblBlogThreads, body, '" & tstr & "' )
) tbl1
group by [key]) AS Key_Tbl
INNER JOIN tblBlogThreads ON tblBlogThreads.BlogthreadID = Key_Tbl.[key] 
order by [rank] desc

Open in new window

0
 
LVL 25

Accepted Solution

by:
imitchie earned 325 total points
ID: 20379997
create procedure myproc ( @tsq varchar(100) )
as
select
Key_Tbl.[key], tblBlogThreads.BlogThreadNum,  
tblBlogThreads.Body,tblBlogThreads.PublishDate,
tblBlogThreads.Title,
tblBlogThreads.Teaser,
tblBlogThreads.MetaKeywords,  
[rank]
from
(select [key], max(rank) as rank from
(select [key], rank + 2000 as rank from freetexttable(tblBlogThreads, title, @tsq )
 union all
 select [key], rank + 1000 from freetexttable(tblBlogThreads, keywords, @tsq )
 union all
 select [key], rank from freetexttable(tblBlogThreads, body, @tsq )
) tbl1
group by [key]) AS Key_Tbl
INNER JOIN tblBlogThreads ON tblBlogThreads.BlogthreadID = Key_Tbl.[key]
order by [rank] desc
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

777 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