Solved

Search Freetext Multiple Columns SQL2000

Posted on 2007-11-29
7
448 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
[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
  • 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
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 
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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

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 …
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

749 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