
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 `bt_zz_DPageItemType` (`type`, `title`, `sorter`) VALUES
('Search_Content_', 'Search Content Block', 360);

ALTER TABLE `bt_zz_HtmlBlockContent` ADD `searchContent` TEXT NOT NULL AFTER `content`;
ALTER TABLE `bt_zz_DraftHtmlBlockContent` ADD `searchContent` TEXT NOT NULL AFTER `content`;

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

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

--
--

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

--
--

INSERT INTO `bt_zz_DPageItemType` (`type`, `title`, `sorter`) VALUES
('Search_Faq_', 'Search FAQ', 390);

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

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

--
--

INSERT INTO `bt_zz_DPageItemType` (`type`, `title`, `sorter`) VALUES
('Search_People_', 'Search Our Team', 400);

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

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

--
--

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

--
--

DROP FUNCTION IF EXISTS strip_tags;