Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Search Freetext Multiple Columns SQL2000

Posted on 2007-11-29
7
Medium Priority
?
452 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 1300 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

688 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