In realtà sto lavorando a un sito Web in cui ci sono due tabelle, quasi identiche, in cui MATCH CONTRO funziona su una, ma non sull'altra. Per scoprire perché ho cercato di ridurlo a un semplice, "Facciamo una semplice tabella di lavoro" - ma non è così.MySQL MATCH CONTRO non funziona
Sto facendo test con phpMyAdmin e questo è MySQL 5.1.41.
Il test mi costruisco usato il seguente per definire la tabella di ...
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`);
e quando faccio una SHOW INDEX FROM prova vedo che c'è una chiave FULLTEXT che comprende titolo e il corpo.
inserisco un paio di righe con
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.');
(alcuni contenuti corpo rimosso per brevità)
e poi quando corro
SELECT * FROM `test` WHERE MATCH (`title`, `body`) AGAINST ('consectetur');
ottengo un set di risultati vuoto - no righe trovate ma se corro
SELECT * FROM `test` WHERE `body` LIKE '%consectetur%';
quindi viene trovato un record.
Sebbene io abbia molta esperienza con MySQL, questa è la prima volta che utilizzo MATCH, quindi sto facendo qualcosa di stupido? Perché non funziona? L'indice deve essere costruito (ho fatto una RIPARAZIONE sul tavolo) o è tutto dovuto avvenire automaticamente?
Solo per informazioni, il tavolo che funziona viene definito con
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;
e quello che mi sta causando problemi e mi ha mandato giù questo percorso è
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;
Anche se ho cercato di definire il secondo esattamente come il primo e ancora non funziona.
Mille grazie. Questo è risolto. – Ken