
DROP FUNCTION IF EXISTS strip_tags;
DELIMITER $$$
CREATE FUNCTION strip_tags( x text) RETURNS text
LANGUAGE SQL NOT DETERMINISTIC READS SQL DATA
BEGIN
DECLARE sstart INT UNSIGNED;
DECLARE ends INT UNSIGNED;
SET x = CONCAT('<p>', x, '</p>');
SET sstart = LOCATE('<', x, 1);
REPEAT
SET ends = LOCATE('>', x, sstart);
SET x = CONCAT(SUBSTRING( x, 1 ,sstart -1), SUBSTRING(x, ends +1 )) ;
SET sstart = LOCATE('<', x, 1);
UNTIL sstart < 1 END REPEAT;
return x;
END $$$
DELIMITER ;

--
--
INSERT INTO `be_zz_DPageItemType` (`type`, `title`, `sorter`) VALUES
('Search_Content_', 'Search Content Block', 320);

ALTER TABLE `be_zz_HtmlBlockContent` ADD `searchContent` TEXT NOT NULL AFTER `content`;
ALTER TABLE `be_zz_DraftHtmlBlockContent` ADD `searchContent` TEXT NOT NULL AFTER `content`;

UPDATE `be_zz_HtmlBlockContent`
SET `searchContent` = strip_tags(`content`);

UPDATE `be_zz_DraftHtmlBlockContent`
SET `searchContent` = strip_tags(`content`);

--
--

INSERT INTO `be_zz_DPageItemType` (`type`, `title`, `sorter`) VALUES
('Search_News_', 'Search News', 330);

ALTER TABLE `be_News` ADD `searchContent` TEXT NOT NULL AFTER `content`;

UPDATE `be_News`
SET `searchContent` = strip_tags(`content`);

--
--


INSERT INTO `be_zz_DPageItemType` (`type`, `title`, `sorter`) VALUES
('Search_Faq_', 'Search FAQ', 350);

ALTER TABLE `be_Faq` ADD `searchContent` TEXT NOT NULL AFTER `answer`;

UPDATE `be_Faq`
SET `searchContent` = strip_tags(`answer`);

--
--

INSERT INTO `be_zz_DPageItemType` (`type`, `title`, `sorter`) VALUES
('Search_Empty_', 'Empty Search Result', 360);

--
--

ALTER TABLE `be_History` ADD `searchContent` TEXT NOT NULL AFTER `description`;

UPDATE `be_History`
SET `searchContent` = strip_tags(`description`);

--
--

INSERT INTO `be_zz_DPageItemType` (`type`, `title`, `sorter`) VALUES
('Search_Story_', 'Search Stories', 370);

ALTER TABLE `be_Story` ADD `searchContent` TEXT NOT NULL AFTER `description`;

UPDATE `be_Story`
SET `searchContent` = strip_tags(`description`);

--
--

INSERT INTO `be_zz_DPageItemType` (`type`, `title`, `sorter`) VALUES
('Search_People_', 'Search People', 380);

ALTER TABLE `be_People` ADD `searchContent` TEXT NOT NULL AFTER `fullBio`;

UPDATE `be_People`
SET `searchContent` = strip_tags(`fullBio`);

ALTER TABLE `be_People` ADD `rawTerritoryLeaderInfo` TEXT NOT NULL AFTER `territoryLeaderInfo`;

UPDATE `be_People`
SET `rawTerritoryLeaderInfo` = strip_tags(`territoryLeaderInfo`);

--
--

INSERT INTO `be_zz_DPageItemType` (`type`, `title`, `sorter`) VALUES
('Search_Product_', 'Search Product', 390);

ALTER TABLE `be_Product` CHANGE `installations` `installations` MEDIUMTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;

ALTER TABLE `be_Product` ADD `searchContent` TEXT NOT NULL AFTER `description`;
ALTER TABLE `be_Product` ADD `rawInstallations` TEXT NOT NULL AFTER `installations`;
ALTER TABLE `be_Product` ADD `rawDimension` TEXT NOT NULL AFTER `dimension`;
ALTER TABLE `be_Product` ADD `rawWeight` TEXT NOT NULL AFTER `weight`;


UPDATE `be_Product`
SET 
`searchContent` = strip_tags(`description`),
`rawInstallations` = strip_tags(`installations`),
`rawDimension` = strip_tags(`dimension`),
`rawWeight` = strip_tags(`weight`);

--
--

INSERT INTO `be_zz_DPageItemType` (`type`, `title`, `sorter`) VALUES ('Search_Form_', 'Search Form', 450);

--
--

DROP FUNCTION IF EXISTS strip_tags;