[Groonga-mysql-commit] mroonga/mroonga [master] support '*D+', '*D-', '*DOR' operator in boolean mode. refs #657

Back to archive index

null+****@clear***** null+****@clear*****
2011年 10月 27日 (木) 12:18:31 JST


Kouhei Sutou	2011-10-27 03:18:31 +0000 (Thu, 27 Oct 2011)

  New Revision: f4ff9c1b19b02bdab13f5d0bd6bf1c2e89d7bb81

  Log:
    support '*D+', '*D-', '*DOR' operator in boolean mode. refs #657

  Added files:
    test/sql/groonga_storage/r/fulltext_boolean_mode_pragma_default_operator.result
    test/sql/groonga_storage/t/fulltext_boolean_mode_pragma_default_operator.test
    test/sql/groonga_wrapper/r/fulltext_boolean_mode_pragma_default_operator.result
    test/sql/groonga_wrapper/t/fulltext_boolean_mode_pragma_default_operator.test
  Modified files:
    ha_mroonga.cc

  Modified: ha_mroonga.cc (+30 -1)
===================================================================
--- ha_mroonga.cc    2011-10-27 02:49:04 +0000 (4797056)
+++ ha_mroonga.cc    2011-10-27 03:18:31 +0000 (dd2196f)
@@ -5252,7 +5252,36 @@ FT_INFO *ha_mroonga::generic_ft_init_ext(uint flags, uint key_nr, String *key)
   if (flags & FT_BOOL) {
     const char *keyword = key->ptr();
     uint keyword_length = key->length();
+    grn_operator default_operator = GRN_OP_OR;
+    // WORKAROUND: support only '*D+', '*D-' and '*DOR' pragma.
+    if (keyword_length > 0) {
+      if (keyword[0] == '*' && keyword_length > 1) {
+        switch (keyword[1]) {
+        case 'D':
+          if (keyword_length > 2 && keyword[2] == '+') {
+            default_operator = GRN_OP_AND;
+            keyword += 3;
+            keyword_length -= 3;
+          } else if (keyword_length > 2 && keyword[2] == '-') {
+            default_operator = GRN_OP_OR;
+            keyword += 3;
+            keyword_length -= 3;
+          } else if (keyword_length > 3 && memcmp(keyword + 2, "OR", 2) == 0) {
+            default_operator = GRN_OP_OR;
+            keyword += 4;
+            keyword_length -= 4;
+          }
+          break;
+        default:
+          break;
+        }
+      }
+    }
     // WORKAROUND: ignore the first '+' to support "+apple macintosh" pattern.
+    while (keyword_length > 0 && keyword[0] == ' ') {
+      keyword++;
+      keyword_length--;
+    }
     if (keyword_length > 0 && keyword[0] == '+') {
       keyword++;
       keyword_length--;
@@ -5261,7 +5290,7 @@ FT_INFO *ha_mroonga::generic_ft_init_ext(uint flags, uint key_nr, String *key)
     grn_rc rc;
     rc = grn_expr_parse(info->ctx, expression,
                         keyword, keyword_length,
-                        match_columns, GRN_OP_MATCH, GRN_OP_OR,
+                        match_columns, GRN_OP_MATCH, default_operator,
                         expression_flags);
     // TODO: check rc
     grn_table_select(info->ctx, info->table, expression,

  Added: test/sql/groonga_storage/r/fulltext_boolean_mode_pragma_default_operator.result (+45 -0) 100644
===================================================================
--- /dev/null
+++ test/sql/groonga_storage/r/fulltext_boolean_mode_pragma_default_operator.result    2011-10-27 03:18:31 +0000 (c1e4298)
@@ -0,0 +1,45 @@
+drop table if exists diaries;
+set names utf8;
+create table diaries (
+id int primary key,
+title varchar(255),
+content text,
+fulltext index (content)
+) default charset utf8;
+show create table diaries;
+Table	Create Table
+diaries	CREATE TABLE `diaries` (
+  `id` int(11) NOT NULL,
+  `title` varchar(255) DEFAULT NULL,
+  `content` text,
+  PRIMARY KEY (`id`),
+  FULLTEXT KEY `content` (`content`)
+) ENGINE=groonga DEFAULT CHARSET=utf8
+insert into diaries values(1, "Hello", "今日からはじめました。");
+insert into diaries values(2, "天気", "明日の富士山の天気について");
+insert into diaries values(3, "富士山", "今日も天気がよくてきれいに見える。");
+select * from diaries where match(content) against("今日 天気" in boolean mode);
+id	title	content
+1	Hello	今日からはじめました。
+3	富士山	今日も天気がよくてきれいに見える。
+2	天気	明日の富士山の天気について
+select * from diaries where match(content) against("*D+ 今日 天気" in boolean mode);
+id	title	content
+3	富士山	今日も天気がよくてきれいに見える。
+select * from diaries where match(content) against("*D- 今日 天気" in boolean mode);
+id	title	content
+1	Hello	今日からはじめました。
+3	富士山	今日も天気がよくてきれいに見える。
+2	天気	明日の富士山の天気について
+select * from diaries where match(content) against("*D- +今日 +天気" in boolean mode);
+id	title	content
+3	富士山	今日も天気がよくてきれいに見える。
+select * from diaries where match(content) against("*DOR 今日 天気" in boolean mode);
+id	title	content
+1	Hello	今日からはじめました。
+3	富士山	今日も天気がよくてきれいに見える。
+2	天気	明日の富士山の天気について
+select * from diaries where match(content) against("*DOR +今日 +天気" in boolean mode);
+id	title	content
+3	富士山	今日も天気がよくてきれいに見える。
+drop table diaries;

  Added: test/sql/groonga_storage/t/fulltext_boolean_mode_pragma_default_operator.test (+48 -0) 100644
===================================================================
--- /dev/null
+++ test/sql/groonga_storage/t/fulltext_boolean_mode_pragma_default_operator.test    2011-10-27 03:18:31 +0000 (299ca78)
@@ -0,0 +1,48 @@
+# Copyright(C) 2011 Kouhei Sutou <kou****@clear*****>
+#
+# 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+--source suite/groonga_include/groonga_init.inc
+
+--disable_warnings
+drop table if exists diaries;
+--enable_warnings
+
+set names utf8;
+create table diaries (
+  id int primary key,
+  title varchar(255),
+  content text,
+  fulltext index (content)
+) default charset utf8;
+show create table diaries;
+
+insert into diaries values(1, "Hello", "今日からはじめました。");
+insert into diaries values(2, "天気", "明日の富士山の天気について");
+insert into diaries values(3, "富士山", "今日も天気がよくてきれいに見える。");
+
+select * from diaries where match(content) against("今日 天気" in boolean mode);
+
+select * from diaries where match(content) against("*D+ 今日 天気" in boolean mode);
+
+select * from diaries where match(content) against("*D- 今日 天気" in boolean mode);
+select * from diaries where match(content) against("*D- +今日 +天気" in boolean mode);
+
+select * from diaries where match(content) against("*DOR 今日 天気" in boolean mode);
+select * from diaries where match(content) against("*DOR +今日 +天気" in boolean mode);
+
+drop table diaries;
+
+--source suite/groonga_include/groonga_deinit.inc

  Added: test/sql/groonga_wrapper/r/fulltext_boolean_mode_pragma_default_operator.result (+45 -0) 100644
===================================================================
--- /dev/null
+++ test/sql/groonga_wrapper/r/fulltext_boolean_mode_pragma_default_operator.result    2011-10-27 03:18:31 +0000 (42ebf8f)
@@ -0,0 +1,45 @@
+drop table if exists diaries;
+set names utf8;
+create table diaries (
+id int primary key,
+title varchar(255),
+content text,
+fulltext index (content)
+) default charset utf8 comment = 'engine "innodb"';
+show create table diaries;
+Table	Create Table
+diaries	CREATE TABLE `diaries` (
+  `id` int(11) NOT NULL,
+  `title` varchar(255) DEFAULT NULL,
+  `content` text,
+  PRIMARY KEY (`id`),
+  FULLTEXT KEY `content` (`content`)
+) ENGINE=groonga DEFAULT CHARSET=utf8 COMMENT='engine "innodb"'
+insert into diaries values(1, "Hello", "今日からはじめました。");
+insert into diaries values(2, "天気", "明日の富士山の天気について");
+insert into diaries values(3, "富士山", "今日も天気がよくてきれいに見える。");
+select * from diaries where match(content) against("今日 天気" in boolean mode);
+id	title	content
+1	Hello	今日からはじめました。
+3	富士山	今日も天気がよくてきれいに見える。
+2	天気	明日の富士山の天気について
+select * from diaries where match(content) against("*D+ 今日 天気" in boolean mode);
+id	title	content
+3	富士山	今日も天気がよくてきれいに見える。
+select * from diaries where match(content) against("*D- 今日 天気" in boolean mode);
+id	title	content
+1	Hello	今日からはじめました。
+3	富士山	今日も天気がよくてきれいに見える。
+2	天気	明日の富士山の天気について
+select * from diaries where match(content) against("*D- +今日 +天気" in boolean mode);
+id	title	content
+3	富士山	今日も天気がよくてきれいに見える。
+select * from diaries where match(content) against("*DOR 今日 天気" in boolean mode);
+id	title	content
+1	Hello	今日からはじめました。
+3	富士山	今日も天気がよくてきれいに見える。
+2	天気	明日の富士山の天気について
+select * from diaries where match(content) against("*DOR +今日 +天気" in boolean mode);
+id	title	content
+3	富士山	今日も天気がよくてきれいに見える。
+drop table diaries;

  Added: test/sql/groonga_wrapper/t/fulltext_boolean_mode_pragma_default_operator.test (+48 -0) 100644
===================================================================
--- /dev/null
+++ test/sql/groonga_wrapper/t/fulltext_boolean_mode_pragma_default_operator.test    2011-10-27 03:18:31 +0000 (5c6874b)
@@ -0,0 +1,48 @@
+# Copyright(C) 2011 Kouhei Sutou <kou****@clear*****>
+#
+# 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+--source suite/groonga_include/groonga_init.inc
+
+--disable_warnings
+drop table if exists diaries;
+--enable_warnings
+
+set names utf8;
+create table diaries (
+  id int primary key,
+  title varchar(255),
+  content text,
+  fulltext index (content)
+) default charset utf8 comment = 'engine "innodb"';
+show create table diaries;
+
+insert into diaries values(1, "Hello", "今日からはじめました。");
+insert into diaries values(2, "天気", "明日の富士山の天気について");
+insert into diaries values(3, "富士山", "今日も天気がよくてきれいに見える。");
+
+select * from diaries where match(content) against("今日 天気" in boolean mode);
+
+select * from diaries where match(content) against("*D+ 今日 天気" in boolean mode);
+
+select * from diaries where match(content) against("*D- 今日 天気" in boolean mode);
+select * from diaries where match(content) against("*D- +今日 +天気" in boolean mode);
+
+select * from diaries where match(content) against("*DOR 今日 天気" in boolean mode);
+select * from diaries where match(content) against("*DOR +今日 +天気" in boolean mode);
+
+drop table diaries;
+
+--source suite/groonga_include/groonga_deinit.inc




Groonga-mysql-commit メーリングリストの案内
Back to archive index