mysql> SELECT * FROM articles WHERE MATCH (title,body)AGAINST ('+MySQL -YourSQL' IN BOOLEAN MODE);+----+-----------------------+-------------------------------------+| id | title | body |+----+-----------------------+-------------------------------------+| 1 | MySQL Tutorial | DBMS stands for DataBase ... || 2 | How To Use MySQL Well | After you went through a ... || 3 | Optimizing MySQL | In this tutorial, we show ... || 4 | 1001 MySQL Tricks | 1. Never run mysqld as root. 2. ... || 6 | MySQL Security | When configured properly, MySQL ... |+----+-----------------------+-------------------------------------+
${IDF} = log10( ${total_records} ${matching_records} )
${TF} * ${IDF}
${rank} = ${TF} * ${IDF} * ${IDF}
mysql> CREATE TABLE articles (id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,title VARCHAR(200),body TEXT,FULLTEXT (title,body)) ENGINE=InnoDB;Query OK, 0 rows affected (1.04 sec)mysql> INSERT INTO articles (title,body) VALUES('MySQL Tutorial','This database tutorial ...'),("How To Use MySQL",'After you went through a ...'),('Optimizing Your Database','In this database tutorial ...'),('MySQL vs. YourSQL','When comparing databases ...'),('MySQL Security','When configured properly, MySQL ...'),('Database, Database, Database','database database database'),('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),('MySQL Full-Text Indexes', 'MySQL fulltext indexes use a ..');Query OK, 8 rows affected (0.06 sec)Records: 8 Duplicates: 0 Warnings: 0mysql> SELECT id, title, body, MATCH (title,body) AGAINST ('database' IN BOOLEAN MODE)AS score FROM articles ORDER BY score DESC;+----+------------------------------+-------------------------------------+---------------------+| id | title | body | score |+----+------------------------------+-------------------------------------+---------------------+| 6 | Database, Database, Database | database database database | 1.0886961221694946 || 3 | Optimizing Your Database | In this database tutorial ... | 0.36289870738983154 || 1 | MySQL Tutorial | This database tutorial ... | 0.18144935369491577 || 2 | How To Use MySQL | After you went through a ... | 0 || 4 | MySQL vs. YourSQL | When comparing databases ... | 0 || 5 | MySQL Security | When configured properly, MySQL ... | 0 || 7 | 1001 MySQL Tricks | 1. Never run mysqld as root. 2. ... | 0 || 8 | MySQL Full-Text Indexes | MySQL fulltext indexes use a .. | 0 |+----+------------------------------+-------------------------------------+---------------------+8 rows in set (0.00 sec)
${IDF} = log10( 8 3 ) = 0.42596873216370745
${rank} = ${TF} * ${IDF} * ${IDF}
mysql> SELECT 6*log10(8/3)*log10(8/3);+-------------------------+| 6*log10(8/3)*log10(8/3) |+-------------------------+| 1.088696164686938 |+-------------------------+1 row in set (0.00 sec)
${rank} = ${TF} * ${IDF} * ${IDF} + ${TF} * ${IDF} * ${IDF}
mysql> SELECT id, title, body, MATCH (title,body) AGAINST ('mysql tutorial' IN BOOLEAN MODE)AS score FROM articles ORDER BY score DESC;+----+------------------------------+-------------------------------------+----------------------+| id | title | body | score |+----+------------------------------+-------------------------------------+----------------------+| 1 | MySQL Tutorial | This database tutorial ... | 0.7405621409416199 || 3 | Optimizing Your Database | In this database tutorial ... | 0.3624762296676636 || 5 | MySQL Security | When configured properly, MySQL ... | 0.031219376251101494 || 8 | MySQL Full-Text Indexes | MySQL fulltext indexes use a .. | 0.031219376251101494 || 2 | How To Use MySQL | After you went through a ... | 0.015609688125550747 || 4 | MySQL vs. YourSQL | When comparing databases ... | 0.015609688125550747 || 7 | 1001 MySQL Tricks | 1. Never run mysqld as root. 2. ... | 0.015609688125550747 || 6 | Database, Database, Database | database database database | 0 |+----+------------------------------+-------------------------------------+----------------------+8 rows in set (0.00 sec)
mysql> SELECT (1*log10(8/6)*log10(8/6)) + (2*log10(8/2)*log10(8/2));+-------------------------------------------------------+| (1*log10(8/6)*log10(8/6)) + (2*log10(8/2)*log10(8/2)) |+-------------------------------------------------------+| 0.7405621541938003 |+-------------------------------------------------------+1 row in set (0.00 sec)
文章转载自数据库杂货铺,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




