Groups | Blog | Home
all groups > sql server (microsoft) > march 2005 >

sql server (microsoft) : simple search engine functionality


Madhivanan
3/21/2005 9:20:42 PM

Try this

Select sum(weight) from(
select ID, content_ID, 3 as 'weight'
from tblPage
where keywords LIKE '%test%'
union
select ID, content_ID, 2
from tblPage
where title LIKE '%test%'
) T

Madhivanan
rapataa
3/22/2005 12:13:25 AM
hi,

I'm building a simple search engine functionality for a client searching the
keyword and title and content of a page:

----
select ID, content_ID, 3 as 'weight'
from tblPage
where keywords LIKE '%test%'

union

select ID, content_ID, 2
from tblPage
where title LIKE '%test%'
-----

this results in a nice resultset, but now I want to sum the 'weight' values
so I can order by 'weight'....

Anyone any idea?

dbmonitor
3/22/2005 3:03:15 AM

[quoted text, click to view]

select ID, content_ID, sum(weight)
from ( select ID, content_ID, 3 as 'weight'
from tblPage
where keywords LIKE '%test%'

union

select ID, content_ID, 2
from tblPage
where title LIKE '%test%') as r

--
David Rowland
http://dbmonitor.tripod.com
rapataa
3/22/2005 9:31:52 AM
ah great,
I changed it to the following code, and it works:

----
Select ID, content_ID, sum(weight) weight
from
(
select ID, content_ID, 3 as 'weight'
from tblPage
where keywords LIKE '%test%'

union

select ID, content_ID, 2 as 'weight'
from tblPage
where title LIKE '%test%'
)
faketablename
group by ID, content_ID
order by weight desc

AddThis Social Bookmark Button