有关此主题的stackoverflow中有十多个问题,我阅读了大部分问题,但仍然无法搜索我的数据库...... !!! 这是我的表结构:
$sql = "CREATE TABLE content.htmlLink(
LessonID INT NOT NULL,
LessonTitle VARCHAR(512) NOT NULL COLLATE utf8_general_ci,
LessonContent TEXT NOT NULL COLLATE utf8_general_ci,
storeDate VARCHAR(32) NOT NULL COLLATE utf8_general_ci,
fileName VARCHAR(128) NOT NULL COLLATE utf8_general_ci,
FOREIGN KEY(LessonID) REFERENCES `content`.`html`(id)
);";
和父表:
$sql = "CREATE TABLE content.html(
id INT(11) NOT NULL AUTO_INCREMENT,
title VARCHAR(512) NOT NULL COLLATE utf8_general_ci,
content TEXT NOT NULL COLLATE utf8_general_ci,
storeDate VARCHAR(32) NOT NULL COLLATE utf8_general_ci,
tag1 VARCHAR(32) NOT NULL COLLATE utf8_general_ci,
tag2 VARCHAR(32) COLLATE utf8_general_ci,
tag3 VARCHAR(32) COLLATE utf8_general_ci,
tag4 VARCHAR(32) COLLATE utf8_general_ci,
tag5 VARCHAR(32) COLLATE utf8_general_ci,
PRIMARY KEY(id)
);";
向表格插入信息没有问题
但是,现在我正在尝试为用户创建一个搜索引擎。
我想搜索LessonContent
中是否存在用户模式,所以我写了这一行:
$sql = "SELECT * FROM content.htmllink
WHERE MATCH(LessonTitle,LessonContent) AGAINST('$pattern')";
$query = $conn->query($sql);
//I tried to use bind param
$sql = "SELECT * FROM content.htmllink
WHERE MATCH(LessonTitle,LessonContent) AGAINST('?')";
$prepare = $conn->prepare($sql);
$prepare->execute( array( $pattern ) );
$fetch = $prepare->fetchAll();
//or with IN BOOLEAN MODE arg
$sql = "SELECT * FROM content.htmllink WHERE MATCH(LessonTitle,LessonContent) AGAINST('html', IN BOOLEAN MODE)";
甚至我用特定的模式检查了查询:
$sql = "SELECT * FROM content.htmllink
WHERE MATCH(LessonTitle,LessonContent) AGAINST('html')";
但仍然$ query是错误的。
你能告诉我我的错误在哪里吗?
提前致谢。
我搜索了这个链接:
http://dev.mysql.com/doc/refman/5.5/en/fulltext-search.html
Another site
http://dev.mysql.com/doc/refman/5.5/en/fulltext-query-expansion.html
How to search MySQL database using MATCH AGAINST method that returns only rows that have a particular field value?
How to make MYSQL search for minimum 3 keyword matches?
以及其他许多人......
答案 0 :(得分:1)
InnoDb
(Mysql版本5.6)确实支持FULL TEXT SEARCHES
。正如您所提到的那样,您的版本如下所示它不支持