MySQL MATCH....AGAINST help needed

Discussion in 'PHP' started by Raikia, Mar 27, 2008.

  1. #1
    Hey all. I am having an issue with the MATCH() AGAINST() query in MySQL. I'm not really new at MySQL or at Web Development. This is, however, the first time I have used "MATCH() AGAINST()" before. Let me set this up:

    Table: `sources`

    Rows used (in this example): 'title' - varchar(255)
    'desc' - text

    Indexes: 'IdxText' - title, desc - FULLTEXT



    Row Values:

    1 entry: title = "Hello World"
    desc = "this is a test"


    QUERY:

    $mysql = mysql_query("SELECT * FROM sources WHERE MATCH(`title`,`desc`) AGAINST('".$keywords."')") or die(mysql_error());

    Or more obviously:

    SELECT * FROM sources WHERE MATCH(`title`,`desc`) AGAINST('".$keywords."')


    $keywords = inserted string from user


    Everything that is entered in for $keywords always returns nothing. If "Hello" is inserted, it returns 0 rows. I get no errors (even through myphpadmin).

    If I am seeing this right, it should return the row because it has "Hello World" in the `title` row and I am searching the `title` row (and the `desc`) row for 'Hello'.......no rows are returned.


    If you are wondering why i have the ` around 'title' and 'desc', it is because 'desc' will be interpreted as "descending" by MySQL and throw an error.




    If it changes anything, I am using MySQL 5.0.45. I have researched this for about half a day, non-stop. I pretty much turn to you guys as my last resort. Why is this returning no rows?
     
    Raikia, Mar 27, 2008 IP
  2. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #2
    Could this function be similar to the LIKE function?

    If so then try putting % before and after each field you are trying to match the keyword against.

    e.g. (`%title%`,`%desc%`)

     
    Weirfire, Mar 28, 2008 IP
  3. tamilsoft

    tamilsoft Banned

    Messages:
    1,155
    Likes Received:
    78
    Best Answers:
    0
    Trophy Points:
    0
    #3
    What is your table types, Is it MyIsam?
     
    tamilsoft, Mar 28, 2008 IP
  4. Raikia

    Raikia Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Nope, that doesn't work. Neither in the MATCH clause nor in the AGAINST clause


    Yes, it is MyIsam and the Collation is latin1_swedish_ci.


    Any other ideas?
     
    Raikia, Mar 28, 2008 IP
  5. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #5
    If you have only one record then you should consider INSERTing more than 4 records. But keeping in mind 50% threshold.
     
    mwasif, Mar 28, 2008 IP
  6. Raikia

    Raikia Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I have 6 entries and it still does not work.


    What is the 50% threshold?
     
    Raikia, Mar 28, 2008 IP
  7. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #7
    From MySQL Manual
    I can not post links :( Try searching on google for MySQL FULLTEXT search and click on the first record.
     
    mwasif, Mar 28, 2008 IP
  8. Raikia

    Raikia Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Ah! I inserted 7 rows and typing "hello world" returns the 1 row that has it. However, just typing "hello" does not return anything (even though only 1 out of 7 rows has it).


    Thanks so much!
     
    Raikia, Mar 28, 2008 IP
  9. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #9
    Run this query in MySQL and post back what it returns
    SHOW VARIABLES LIKE 'ft_min_word_len';
    Code (markup):
     
    mwasif, Mar 28, 2008 IP
  10. Raikia

    Raikia Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Variable_name

    ft_min_word_len



    Value
    4
     
    Raikia, Mar 28, 2008 IP
  11. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #11
    Then it should return the result when querying only for hello. Check the stop word list by
    SHOW VARIABLES LIKE 'ft_stopword_file';
    Code (markup):
    Read full page here dev.mysql.com/doc/refman/5.0/en/fulltext-fine-tuning.html
     
    mwasif, Mar 28, 2008 IP
  12. Raikia

    Raikia Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    The result of the stopword file just says "(built-in)". Maybe it is on the stopword list for my hosts' server?
     
    Raikia, Mar 28, 2008 IP
  13. natski

    natski Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    you must include the "IN BOOLEAN MODE" after your AGAINST keyword..
     
    natski, Apr 9, 2008 IP