我實際上正在一個網站上有兩張表,幾乎完全相同,其中MATCH AGAINST在一個上工作,而在另一個上工作。爲了找出爲什麼我試圖將其簡化爲一個簡單的「讓我們做一個簡單的工作表」 - 但事實並非如此。MySQL MATCH AGAINST無法正常工作
我正在用phpMyAdmin進行測試,這是MySQL 5.1.41。
我建立使用的測試如下定義表格...
CREATE TABLE IF NOT EXISTS `test` (
`id` int(11) NOT NULL,
`title` text NOT NULL,
`body` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
ALTER TABLE `test` ADD FULLTEXT (`title`, `body`);
,當我做SHOW指數從測試中,我看到,有包括標題和身體全文鍵。
我插入一些記錄與
INSERT INTO `test` (`id`, `title`, `body`) VALUES
('1', 'Lorem Ipsum', 'Lorem ipsum dolor sit amet, consectetur ... lacus porta euismod.'),
('2', 'Lorem Ipsum (cont)', 'Nunc leo massa, vulputate ... euismod fringilla.');
(身體有些內容簡潔,刪除)
,然後當我運行
SELECT * FROM `test` WHERE MATCH (`title`, `body`) AGAINST ('consectetur');
我得到一個空的結果集 - 無行發現,但如果我運行
SELECT * FROM `test` WHERE `body` LIKE '%consectetur%';
然後找到記錄。
雖然我在MySQL方面有很多經驗,但這是我第一次使用MATCH,所以我在做一些愚蠢的事情?爲什麼這不起作用?是否需要建立索引(我在桌面上進行了REPAIR)還是應該自動發生?
只是爲了信息,其工作表是用
CREATE TABLE IF NOT EXISTS `web_pages1` (
`id` int(11) NOT NULL,
`title` varchar(255) DEFAULT NULL,
`slug` varchar(255) DEFAULT NULL,
`meta_keywords` text,
`meta_description` text,
`snippet` text,
`body` mediumtext,
`created_by` int(11) DEFAULT NULL,
`date_created` datetime DEFAULT NULL,
`date_published` date DEFAULT NULL,
`author` varchar(255) DEFAULT NULL,
`edited_by` int(11) DEFAULT NULL,
`date_edited` datetime DEFAULT NULL,
`status` tinyint(4) NOT NULL DEFAULT '1',
`parent_id` tinyint(11) DEFAULT NULL,
`menu_id` int(11) DEFAULT NULL,
`short_name` varchar(255) DEFAULT NULL,
`sort_order` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
FULLTEXT KEY `search` (`title`,`slug`,`meta_keywords`,`meta_description`,`snippet`,`body`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
並導致我的問題,給我發了這條路線的一個定義是
CREATE TABLE IF NOT EXISTS `web_news1` (
`id` int(11) NOT NULL,
`title` varchar(255) NOT NULL,
`slug` varchar(255) NOT NULL,
`meta_keywords` text,
`meta_description` text,
`snippet` text NOT NULL,
`body` text NOT NULL,
`created_by` int(11) NOT NULL,
`date_created` datetime NOT NULL,
`date_published` date DEFAULT NULL,
`author` varchar(255) DEFAULT NULL,
`edited_by` int(11) DEFAULT NULL,
`date_edited` datetime DEFAULT NULL,
`status` tinyint(4) DEFAULT '0',
PRIMARY KEY (`id`),
FULLTEXT KEY `search` (`title`,`slug`,`meta_keywords`,`meta_description`,`snippet`,`body`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
雖然我已經試過定義第二個完全像第一個,但它仍然不起作用。
非常感謝。這是整理它。 – Ken 2013-02-08 17:32:13