mysql全文检索match() against

mysql 本身提供了一种叫做全文搜索的技术

CREATE TABLE articles (
   title VARCHAR(200),
   body TEXT,FULLTEXT (title,body)                       //注意这里

创建表的 mysql 语句, 其中最后一句  FULLTEXT (title,body)就是为 title 和 body 创建一个 全文搜索,也就是 以后 方便搜索 标题 和标题正文的内容

查看表的抓紧索引  show indexs from 表名

show index from articles;


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 表名 WHERE MATCH (全文搜索表字段) AGAINST ('搜索字符串')

SELECT * FROM articles WHERE MATCH(title,body) AGAINST ('database')                       ; match表示要找的列,而against表示要搜索的条件

SELECT * FROM articles WHERE MATCH(title,body) AGAINST ('+MySQL -YourSQL'IN BOOLEAN MODE);   搜索title和body中包含MySQL,但是不能有YourSQL的结果  。

上面的方式是全文搜索和表同时建立,也可以在建立表之后在添加全文搜索alter table articles add fulltext index(title,body);



MYSQL match against 疑问


rnrn-- phpMyAdmin SQL Dumprn-- version 2.10.2rn-- http://www.phpmyadmin.netrn-- rn-- 主机: localhostrn-- 生成日期: 2013 年 01 月 21 日 03:14rn-- 服务器版本: 5.0.45rn-- PHP 版本: 5.2.3rnrnSET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";rnrn-- rn-- 数据库: `test`rn-- rnrn-- --------------------------------------------------------rnrn-- rn-- 表的结构 `city`rn-- rnrnCREATE TABLE `city` (rn `city_id` int(11) NOT NULL auto_increment,rn `city` varchar(50) NOT NULL,rn `pos` varchar(50) NOT NULL,rn `level` tinyint(4) NOT NULL,rn PRIMARY KEY (`city_id`),rn FULLTEXT KEY `city` (`city`)rn) ENGINE=MyISAM DEFAULT CHARSET=gbk AUTO_INCREMENT=11 ;rnrn-- rn-- 导出表中的数据 `city`rn-- rnrnINSERT INTO `city` VALUES (1, '中国', '1', 1);rnINSERT INTO `city` VALUES (2, '广州天河区', '1,2', 2);rnINSERT INTO `city` VALUES (3, '深圳', '1,3', 2);rnINSERT INTO `city` VALUES (4, '宝安', '1,3,4', 3);rnINSERT INTO `city` VALUES (5, '南头', '1,3,5', 3);rnINSERT INTO `city` VALUES (6, '福田', '1,3,6', 3);rnINSERT INTO `city` VALUES (7, '天河', '1,2,7', 3);rnINSERT INTO `city` VALUES (8, '沙河', '1,2,7,8', 4);rnINSERT INTO `city` VALUES (9, '沙河', '1,2,7,9', 4);rnINSERT INTO `city` VALUES (10, 'hello world my friend', '', 0);rnrnSELECT * rnFROM `city` rnWHERE MATCH (rn`city`rn)rnAGAINST (rn'hello'rn)rnrn上述sql 匹配不了city_id为10的记录 为什么呢? 匹配 AGAINST ('world') 就可以,应该不是长度问题。 求助大神,先谢谢啦!!! 论坛

Against Mammoths


Problem DescriptionnBack to year 3024, humans finally developed a new technology that enables them to conquer the alien races. The new technology made it possible to produce huge spaceships known as Saber Tooth spaceships as powerful as the aliens' defending mammoths. At that time, humans ruled several planets while some others were under control of the aliens. Using Saber Tooth ships, humans finally defeated aliens and this became the first Planet War in history. Our goal is to run a simulation of the ancient war to verify some historical hypotheses. nnProducing each spaceship takes an amount of time which is constant for each planet but may vary among different planets. We call the number of spaceships each planet can produce in a year, the production rate of that planet. Note that each planet has a number of spaceships in it initially (before the simulation starts). The planets start producing ships when the simulation starts, so if a planet has nships initially, and has the production rate p, it will have n + p ships at the beginning of year 1, and n + i × p ships at the beginning of year i (years are started from zero).nnBradley Bennett, the commander in chief of the human armies, decided a strategy for the war. For each alien planet A, he chooses a corresponding human planet P, and produces spaceships in P until a certain moment at which he sends all spaceships in P to invade the planet A. No alien planet is invaded by two human planets and no human planet sends its spaceships to two different alien planets. nnThe defense power of the alien planets comes from their powerful mammoths. Each alien planet contains a number of mammoths initially and produces a number of mammoths each year (called the production rate of the planet). When a fight between spaceships and mammoths takes place, the side having the greater number of troops is the winner. If the spaceships win, the alien planet is defeated. In case the number of mammoths and spaceships are equal, the spaceships win.nnThe difficulty with planning this strategy is that it takes some time for the spaceships to reach the alien planets, and during this time, the aliens produce mammoths. The time required for spaceships to travel from each human planet to each alien planet is known. The ships can leave their planets only at the beginning of years (right after the ships are produced) and reach the alien planets at the beginning of years too (right after the mammoths are produced). nnAs an example, consider a human planet with two initial spaceships and production rate three invading an alien planet with two initial mammoths and production rate two. The time required to travel between the two planets is two years and the ships are ordered to leave at year one. In this case, five ships leave the human planet. When they reach the alien planet, they confront eight mammoths and will be defeated during the fight.nnBennett decided to prepare a plan that destroys every alien planet in the shortest possible time. Your task is to write a program to generate such a plan. The output is the shortest possible time (in years) in which every alien planet is defeated.n nnInputnThere are multiple test cases in the input. The first line of each test case contains two numbers H and A which are the number of planets under the control of humans and aliens respectively (both between 1 and 250). The second line of the test case contains H non-negative integers n1 m1 n2 m2 … nH mH. The number ni is the initial number of Saber Tooth spaceships in the ith human planet and mi is the production rate of that planet. The third line contains A non-negative integers which specify the initial number of mammoths and the production rate of the alien planets in the same format as the second line. After the third line, there are H lines each containing A positive integers. The jth number on the ith line shows how many years it takes a spaceship to travel from the ith human planet to the jth alien planet. The last line of the input contains two zero numbers. Every number in the input except H and A is between 0 and 40000.n nnOutputnThe output for each test case contains a single integer which is the minimum time in which all alien planets can be defeated. If it is impossible to destroy all alien planets, the output should be IMPOSSIBLE.n nnSample Inputn2 1n2 3 0 3n2 2n2n2n0 0n nnSample Outputn6n 问答