SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2002
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sorting a reult set

    Hi,

    I was just thinking if I have submitted a query with REGEXP in the WHERE clause, is there a way of ORDERing the result set by how the regular expression matches the record in the field, better meatches appearing first

    Thanks

  2. #2
    Chessplayer kleineme's Avatar
    Join Date
    Apr 2004
    Location
    Germany
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    if you are using a regex there is no such criteria as a "best match". Either it is a match or it isn't

    You may achieve what you want to achieve by creating a fulltext index:

    http://dev.mysql.com/doc/mysql/en/Fulltext_Search.html
    Never ascribe to malice,
    that which can be explained by incompetence.
    Your code should not look unmaintainable, just be that way.

  3. #3
    SitePoint Addict silent's Avatar
    Join Date
    Jun 2004
    Location
    Roaming North America
    Posts
    220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think the poster was wondering how to order by how many matches of a particular expression were found within the stored text? AFAIK, there's is no SET-based way to do this. You would have to do such a ranking algorithm by processing the resultset in PHP or Perl, storing the number of matches found, then re-ordering the resultset array by the number of matches...

    In PHP, I believe the latest stable version of preg_match() allows you to return the count of matches found for the given expression...which would make things easier.

    HTH


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •