Home » Performance » MySQL » make ranking on search result
make ranking on search result [message #3193] Wed, 18 June 2008 03:05 Go to next message
larvus  is currently offline larvus
Messages: 5
Registered: June 2008
Location: india
Junior Member

i hv a product table chemicals(prodname,prodcat,proddesc)

my query is


SELECT prodname FROM bw_product WHERE

prodname like '%sodium chloride%'

OR
prodcateg like '%sodium chloride%'

OR
proddesc like '%sodium chloride%'

order by prodname



"sodium chloride" is searched ,
I am getting a very large number of results and the product "sodium chloride" is nowhere near the top.
The search needs to be configured so that exact (or nearly exact) "prodname" appear at the top,exact (or nearly exact) "prodcateg" appear at the next level and the lowest "ranked" results (ones at bottom) should be ones that had a search hit in the "proddesc" field.

how can i possible these ? pls give the correct query


Larvus
Re: make ranking on search result [message #3204 is a reply to message #3193 ] Thu, 19 June 2008 03:18 Go to previous messageGo to next message
debug  is currently offline debug
Messages: 122
Registered: March 2008
Senior Member

Maybe try this:


SELECT prodname,1 as id FROM bw_product WHERE prodname like '%sodium chloride%'

UNION
SELECT prodcateg,2 as id FROM bw_product WHERE like '%sodium chloride%'

UNION
SELECT proddesc,3 as id FROM bw_product WHERE like '%sodium chloride%'

order by id


Mikhail Solovyev, MySQL Performance Expert
MySQL Performance Blog
MySQL Consulting
Re: make ranking on search result [message #3210 is a reply to message #3204 ] Sat, 21 June 2008 10:04 Go to previous message
larvus  is currently offline larvus
Messages: 5
Registered: June 2008
Location: india
Junior Member

thanks u its working


Larvus
Previous Topic:Help Me optimize my query
Next Topic:Optimize IP Range Join
Goto Forum:
  



Current Time: Fri Nov 21 00:34:07 EST 2008

Total time taken to generate the page: 0.15967 seconds
.:: Contact :: Home :: MySQL Support by Percona.com ::.

Powered by: FUDforum 2.7.5.
Copyright ©2001-2006 FUD Forum Bulletin Board Software

MySQL Performance | Forum authority Badge