Most efficient method of finding related posts in MySQL

Discussion in 'MySQL' started by stevenswing, Mar 26, 2010.

  1. #1
    We have a table with a list of posts (over 10,000), each entry has a Title, ID and other fields.

    We would like to display 5 related posts, based on the keywords of the selected title.

    What would be the most efficient method in the MySQL syntax to extract 5 related posts? LIKE? MATCH?

    I'm new to this so any help would be very much appreciated.
     
    stevenswing, Mar 26, 2010 IP
  2. Gray-Fox

    Gray-Fox Greenhorn

    Messages:
    90
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #2
    Well I'd suggest you using something like this:

    SELECT * FROM `[COLOR="Red"]table_name[/COLOR]` WHERE `[COLOR="Red"]title_field[/COLOR]` LIKE '%[COLOR="Red"]$keyword[/COLOR]%' LIMIT 0 , 5
    Code (markup):
    Let me know if this is what you wants.
     
    Gray-Fox, Mar 26, 2010 IP
  3. stevenswing

    stevenswing Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I am already aware of this syntax, however simply using that will not work... for example...

    SELECT * FROM `table_name` WHERE `title_field` LIKE '%This is a test post%' LIMIT 0 , 5
    Code (markup):
    Will only return the single post with the title "This is a test post"! I want to be able to return 5 related posts from the keywords in the title of the record selected.

    Thank you for your help.
     
    stevenswing, Mar 27, 2010 IP
  4. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #4
    mwasif, Mar 28, 2010 IP
  5. stevenswing

    stevenswing Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Yes, I could enable the title field for a fulltext search. Using PHP, how would I get the results I need? Would I need to break up each word from the title before feeding it into a MySQL full text search? Or could I simply run a MATCH on the full title? Any help would be great, I'm very new to this! Thank you.
     
    stevenswing, Mar 29, 2010 IP
  6. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #6
    Just feed the full title.
     
    mwasif, Mar 29, 2010 IP