//创建表
CREATE TABLE `TEST_FULL_TEXT_SEARCH`
(
`ID` INT NOT NULL AUTO_INCREMENT,
`TEST` VARCHAR(45) NULL,
PRIMARY KEY (`ID`),
FULLTEXT INDEX `FULL_TEXT` (`TEST` ASC)
)
ENGINE = MyISAM;
//插入一些记录
INSERT INTO `TEST_FULL_TEXT_SEARCH`
SELECT 1, 'vikas kumar gupta' UNION ALL
SELECT 2, 'kratika gupta' UNION ALL
SELECT 3, 'kratika sharma' UNION ALL
SELECT 4, 'kratika vikas kumar gupta' UNION ALL
SELECT 5, 'kratika shukla' UNION ALL
SELECT 6, 'chetan kastwar' UNION ALL
SELECT 7, 'kratika kastwar' ;
//现在来到选择查询
SELECT * FROM TEST_FULL_TEXT_SEARCH
WHERE MATCH(test)
AGAINST('kratika' IN NATURAL LANGUAGE MODE WITH QUERY EXPANSION );
//或
SELECT * FROM TEST_FULL_TEXT_SEARCH
WHERE MATCH(test)
AGAINST('kratika' WITH QUERY EXPANSION);
//输出
1 vikas kumar gupta
4 kratika vikas kumar gupta
3 kratika sharma
5 kratika shukla
2 kratika gupta
//现在我们搜索布尔模式
SELECT * FROM TEST_FULL_TEXT_SEARCH
WHERE MATCH(test)
AGAINST('kratika' IN BOOLEAN MODE);
//输出
2 kratika gupta
3 kratika sharma
4 kratika vikas kumar gupta
5 kratika shukla
7 kratika kastwar
//现在我们在布尔模式下搜索没有查询扩展
SELECT * FROM TEST_FULL_TEXT_SEARCH
WHERE MATCH(test)
AGAINST('kratika' IN NATURAL LANGUAGE MODE);
//输出
No result found
请澄清为何不在列表中选择“ kratika kastwar ”
//已编辑
为什么显示' vikas kumar gupta 'IN NATURAL LANGUAGE MODE WITH QUERY EXPANSION
或者在WITH QUERY EXPANSION
的第一级别而不是 kratika 相关结果?
答案 0 :(得分:0)
正在运行
SELECT ID, TEST, MATCH(TEST) AGAINST('kratika' IN NATURAL LANGUAGE MODE ) AS MT FROM TEST_FULL_TEXT_SEARCH
WHERE MATCH(TEST)
AGAINST('kratika' IN NATURAL LANGUAGE MODE );
结果集为空,因为“kratika”一词至少存在于50%的行中。
请检查http://dev.mysql.com/doc/refman/5.5/en//fulltext-natural-language.html,其中提及:
这种技术最适合大型集合(实际上,它是 仔细调整这种方式)。对于非常小的表,单词分配 没有充分反映他们的语义价值,这个模型可能 有时会产生奇怪的结果。
他们有一些样本。
答案 1 :(得分:0)
请看这个链接...... 你会得到一些想法 http://docs.oracle.com/cd/E17952_01/refman-5.1-en/fulltext-query-expansion.html