home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2003 May (DVD) / Macworld Resource DVD May 2003.toast / Data / Software / Bonus / Database / mysql-max-3.23.55.sit / mysql-max-3.23.55-apple-darwi.1 / mysql-test / t / fulltext.test < prev    next >
Encoding:
Text File  |  2003-01-21  |  2.4 KB  |  91 lines  |  [TEXT/ttxt]

  1. #
  2. # Test of fulltext index
  3. #
  4.  
  5. drop table if exists t1,t2,t3;
  6.  
  7. CREATE TABLE t1 (a VARCHAR(200), b TEXT, FULLTEXT (a,b));
  8. INSERT INTO t1 VALUES('MySQL has now support', 'for full-text search'),('Full-text indexes', 'are called collections'),('Only MyISAM tables','support collections'),('Function MATCH ... AGAINST()','is used to do a search'),('Full-text search in MySQL', 'implements vector space model');
  9. select * from t1 where MATCH(a,b) AGAINST ("collections");
  10. select * from t1 where MATCH(a,b) AGAINST ("indexes");
  11. select * from t1 where MATCH(a,b) AGAINST ("indexes collections");
  12. delete from t1 where a like "MySQL%";
  13. update t1 set a='some test foobar' where MATCH a,b AGAINST ('model');
  14. delete from t1 where MATCH(a,b) AGAINST ("indexes");
  15. select * from t1;
  16. drop table t1;
  17.  
  18. #
  19. # Check bug reported by Matthias Urlichs
  20. #
  21.  
  22. CREATE TABLE t1 (
  23.   id int(11),
  24.   ticket int(11),
  25.   KEY ti (id),
  26.   KEY tit (ticket)
  27. );
  28. INSERT INTO t1 VALUES (2,3),(1,2);
  29.  
  30. CREATE TABLE t2 (
  31.   ticket int(11),
  32.   inhalt text,
  33.   KEY tig (ticket),
  34.   fulltext index tix (inhalt)
  35. );
  36. INSERT INTO t2 VALUES (1,'foo'),(2,'bar'),(3,'foobar');
  37.  
  38. select t1.id FROM t2 as ttxt,t1,t1 as ticket2
  39. WHERE ticket2.id = ttxt.ticket AND t1.id = ticket2.ticket and
  40. match(ttxt.inhalt) against ('foobar');
  41.  
  42. # In the following query MySQL didn't use the fulltext index
  43. select t1.id FROM t2 as ttxt,t1 INNER JOIN t1 as ticket2 ON
  44. ticket2.id = ttxt.ticket
  45. WHERE t1.id = ticket2.ticket and match(ttxt.inhalt) against ('foobar');
  46.  
  47. INSERT INTO t1 VALUES (3,3);
  48. select t1.id FROM t2 as ttxt,t1
  49. INNER JOIN t1 as ticket2 ON ticket2.id = ttxt.ticket
  50. WHERE t1.id = ticket2.ticket and
  51.       match(ttxt.inhalt) against ('foobar');
  52.  
  53. # Check that we get 'fulltext' index in SHOW CREATE
  54.  
  55. show keys from t2;
  56. show create table t2;
  57.  
  58. # check for bug reported by Stephan Skusa
  59.  
  60. select * from t2 where MATCH inhalt AGAINST (NULL);
  61.  
  62. # MATCH in HAVING (pretty useless, but still it should work)
  63.  
  64. select * from t2 where  MATCH inhalt AGAINST ('foobar');
  65. select * from t2 having MATCH inhalt AGAINST ('foobar');
  66.  
  67. #
  68. # check of fulltext errors
  69. #
  70.  
  71. CREATE TABLE t3 (
  72.   ticket int(11),
  73.   inhalt text,
  74.   KEY tig (ticket),
  75.   fulltext index tix (inhalt)
  76. );
  77.  
  78. --error 1210
  79. select * from t2 where MATCH inhalt AGAINST (t2.inhalt);
  80.  
  81. --error 1210
  82. select * from t2 where MATCH inhalt AGAINST (t2.inhalt);
  83.  
  84. --error 1191
  85. select * from t2 where MATCH ticket AGAINST ('foobar');
  86.  
  87. --error 1210
  88. select * from t2,t3 where MATCH (t2.inhalt,t3.inhalt) AGAINST ('foobar');
  89.  
  90. drop table t1,t2,t3;
  91.