Not the answer you need?
Register and ask your own question!

make ranking on search result

larvuslarvus EntrantCurrent User Role Beginner
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

Comments

  • debugdebug Contributor Current User Role Beginner
    Maybe something like this:

    SELECT prodname,2 as sort_id FROM bw_product WHERE prodname like '%sodium chloride%'
    UNION
    SELECT prodname,2 as sort_id FROM bw_product WHERE prodcateg like '%sodium chloride%'
    UNION
    SELECT prodname,3 as sort_id FROM bw_product WHERE proddesc like '%sodium chloride%'
    ORDER by sort_id;
  • larvuslarvus Entrant Current User Role Beginner
    its working

    thanks u very much
Sign In or Register to comment.

MySQL, InnoDB, MariaDB and MongoDB are trademarks of their respective owners.
Copyright ©2005 - 2020 Percona LLC. All rights reserved.