# -*- mode: sql; sql-product: mysql -*-
#
# Copyright(C) 2021  Sutou Kouhei <kou@clear-code.com>
#
# 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

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

--disable_warnings
DROP TABLE IF EXISTS diaries;
--enable_warnings

SET NAMES utf8mb4;
CREATE TABLE diaries (
  id INT PRIMARY KEY,
  paragraphs TEXT COMMENT 'FLAGS "COLUMN_VECTOR"',
  FULLTEXT INDEX (paragraphs) COMMENT 'INDEX_FLAGS "WITH_SECTION|WITH_POSITION"'
) DEFAULT CHARSET=utf8mb4;

INSERT INTO diaries
  VALUES(1, '["Today is a good day.", "Very good!", "Good-bye!"]');
INSERT INTO diaries
  VALUES(2, '["Today is a bad day.", "Not good..."]');

SELECT *,
       MATCH(paragraphs) AGAINST("*W1:10,2:2 +good" IN BOOLEAN MODE) AS score
  FROM diaries
 WHERE MATCH(paragraphs) AGAINST("*W1:10,2:2 +good" IN BOOLEAN MODE)
 ORDER BY score DESC;

DROP TABLE diaries;

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