Mysql order by method

Discussion in 'PHP' started by meannn, Jun 3, 2010.

  1. #1
    For example, if the search is

    Norton free 2010 Download

    How to order results like this

    Norton free download
    Norton download
    Norton 2010 for pc

    The first one includes 3 words of the search, so it is first. How to do this, thanks...
     
    meannn, Jun 3, 2010 IP
  2. wigwambam

    wigwambam Peon

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    ORDER
    BY case when `description` LIKE '%norton%' then 1 else 0 end
    + case when `description` LIKE '%free%' then 1 else 0 end
    + case when `description` LIKE '%2010%' then 1 else 0 end
    + case when `description` LIKE '%download%' then 1 else 0 end
    DESC
     
    wigwambam, Jun 3, 2010 IP
  3. georgu

    georgu Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Use MySql FULLTEXT index and pray it works :) There is no simple solution for a general rule for what you want. You can also use SPHINX or another advanced search engine for tricky search rules. But what you want there needs a human decision. I mean, consider that giving that search string i might want to order them differently and so does the search engine. FULLTEXT orders them by relevance ( his relevance not yours :p ). For that specific string the previous solution might work but i don`t think you need mysql and search engines only for that :)
     
    georgu, Jun 3, 2010 IP
  4. mehmetm

    mehmetm Well-Known Member

    Messages:
    134
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #4
    I guess you could run query and get results from DB and sort in array as the way you like..
     
    mehmetm, Jun 3, 2010 IP
  5. meannn

    meannn Peon

    Messages:
    255
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    İyi bir yöntem değil bence :)

    But its not a good method. For example think that user searched "best antivirus" and there are 1,000 results about that. It'll be too bad...
     
    meannn, Jun 3, 2010 IP