# Copyright(C) 2011 Kouhei Sutou
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

# Based on #910.

--source ../../../include/mroonga/have_innodb.inc
--source ../../../include/mroonga/have_mroonga.inc

--disable_warnings
DROP TABLE IF EXISTS videos_master, videos_groonga;
--enable_warnings

CREATE TABLE `videos_master` (
  `id` bigint unsigned NOT NULL,
  `video_id` varchar(64) NOT NULL,
  `description` text,
  `tags_unpack` text,
  PRIMARY KEY (`video_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE `videos_groonga` (
  `id` bigint unsigned NOT NULL,
  `video_id` varchar(64) NOT NULL,
  `description` text,
  `tags_unpack` text,
  PRIMARY KEY (`video_id`),
  FULLTEXT INDEX (`description`),
  FULLTEXT INDEX (`tags_unpack`)
) DEFAULT CHARSET=utf8mb4;


INSERT INTO videos_master VALUES (1, "video-1", "My Familly", "familly human");
INSERT INTO videos_master VALUES (2, "video-2", "My Cat", "family cat");
REPLACE INTO videos_groonga
  SELECT v.id, v.video_id, v.description, NULL
    FROM videos_master AS v
    WHERE v.video_id = (video_id);
SELECT *, MATCH(description) AGAINST("cat") FROM videos_groonga
  WHERE MATCH(description) AGAINST("cat");

INSERT INTO videos_master VALUES (3, "video-3", "My Dog", "family dog");
REPLACE INTO videos_groonga
  SELECT v.id, v.video_id, v.description, NULL
    FROM videos_master AS v
    WHERE v.video_id = (video_id);
SELECT *, MATCH(description) AGAINST("my") FROM videos_groonga
  WHERE MATCH(description) AGAINST("my")
  ORDER BY id;

DROP TABLE videos_master, videos_groonga;

--source ../../../include/mroonga/have_mroonga_deinit.inc
