Help with MATCH AGAINST query

Discussion in 'MySQL' started by hjalte81, Dec 19, 2010.

  1. #1
    Hi guys...

    In my db i have a row where the field 'term' is 'pick-up' and a row where the field 'term' is 'pick-something-up'.

    in my php script I have a variable called $term with 'how-to-pick-up-apples'.

    When I run this query:

    $result = mysql_query("SELECT * FROM data WHERE MATCH (term) AGAINST ('$term' IN BOOLEAN MODE)");
    
    PHP:
    it selects either of the rows in my database, depending on which row comes first.

    I'd like it only to select the row, where there was an exact match.
    Meaning that only the row with 'pick-up' should be selected and not the row with 'pick-something-up'.

    How do I do that?
     
    hjalte81, Dec 19, 2010 IP
  2. georgiivanov

    georgiivanov Member

    Messages:
    62
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    25
    #2
    Then why you are matching in BOOLEAN MODE? If you want to look for 'pick-up' then AGAINST ('pick-up') should do the trick. If you want to do queries like '+word1 +word2 -word3' then you need the boolean mode.
     
    georgiivanov, Dec 20, 2010 IP
  3. hjalte81

    hjalte81 Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Okay, that makes sense. Thx.

    But using:

    $result = mysql_query("SELECT * FROM data WHERE MATCH (term) AGAINST ('$term')");
    PHP:
    ...only gives NULL values.
    Could it have something to do with the hyphen in the words?

    And btw, I'm looking for 'pick-up' inside the 'how-to-pickup-apples' sentence.
     
    hjalte81, Dec 20, 2010 IP
  4. georgiivanov

    georgiivanov Member

    Messages:
    62
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    25
    #4
    It looks like dash (-) is some non-word character in your charset. You should do some hacks to /mysql/share/charsets files to override it somehow...

    In your case you should use IN BOOLEAN MODE or IN NATURAL LANGUAGE MODE WITH QUERY EXPANSION

     
    georgiivanov, Dec 20, 2010 IP