MySQL FULLTEXT help

Discussion in 'Software' started by ibanez, Nov 28, 2006.

  1. ibanez

    ibanez Private E-2

    Hello

    I've been trying to setup a fulltext key on a MySQL table but can't seem to do it right. I'm not sure what I'm missing...

    Here's the sample code that I'm referring too (taken from http://dev.mysql.com/doc/refman/4.1/en/fulltext-search.html)

    Code:
    CREATE TABLE articles (
    id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
    title VARCHAR(200),
    body TEXT,
    FULLTEXT (title,body)
    );
    
    
    INSERT INTO articles (title,body) VALUES
    ('MySQL Tutorial','DBMS stands for DataBase ...'),
    ('How To Use MySQL Well','After you went through a ...'),
    ('Optimizing MySQL','In this tutorial we will show ...'),
    ('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
    ('MySQL vs. YourSQL','In the following database comparison ...'),
    ('MySQL Security','When configured properly, MySQL ...');
    
    SELECT * FROM articles
    WHERE MATCH (title,body) AGAINST ('database');
    Everything works fine....YET, when I take the same idea and change it to this...

    Code:
    CREATE TABLE `new_tbl_name` (
      `tbl_id` int(11) NOT NULL auto_increment,
      `name` varchar(50) NOT NULL default '',
      `keywords` text NOT NULL,
    
      PRIMARY KEY  (`tbl_id`),
      FULLTEXT KEY `keywords` (`keywords`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
    
    SELECT tbl_id, name FROM new_tbl_name WHERE MATCH (keywords) AGAINST ('php')
    
    ...it doesn't seem to work. Any ideas? I do realise that the sample code has two fulltext coloumns, and mine only has one, but i have tried adding the "name" field as a fulltext key.

    There is the word "php" in one of the records...there are also more columns than that too...

    Any help would be greatly appreciated.

    Im using mysql 4, php 4.
     
  2. goldfish

    goldfish Lt. Sushi.DC

    Try taking the 'php' out of brackets. I believe that if you're only matching against one field you shouldn't need to give the query a set.

    EDIT: Never mind that's baloney. I didn't rtfm :)
     
    Last edited: Nov 28, 2006
  3. ibanez

    ibanez Private E-2

    Thats dumb.
    Found the problem....

    You need at least 3 records for this to work.
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds