Navigation Menu

Skip to content

Commit

Permalink
Merge pull request #16 from naoa/add-server-variable-for-vector-delim…
Browse files Browse the repository at this point in the history
…iter

Support vector column delimiter change as experimental feature

Patch by Naoya Murakami. Thanks!!!
  • Loading branch information
kou committed Aug 5, 2014
2 parents 46aebd9 + 5e9269d commit c538a7f
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 1 deletion.
28 changes: 27 additions & 1 deletion ha_mroonga.cpp
Expand Up @@ -519,6 +519,7 @@ char *mrn_default_wrapper_engine = NULL;
static int mrn_lock_timeout = grn_get_lock_timeout();
static char *mrn_libgroonga_version = const_cast<char *>(grn_get_version());
static char *mrn_version = const_cast<char *>(MRN_VERSION);
static char *mrn_vector_column_delimiter = NULL;

typedef enum {
MRN_ACTION_ON_ERROR_ERROR,
Expand Down Expand Up @@ -776,6 +777,30 @@ static MYSQL_THDVAR_LONGLONG(match_escalation_threshold,
LONGLONG_MAX,
0);

static void mrn_vector_column_delimiter_update(THD *thd, struct st_mysql_sys_var *var,
void *var_ptr, const void *save)
{
MRN_DBUG_ENTER_FUNCTION();
const char *new_value = *((const char **)save);
char **old_value_ptr = (char **)var_ptr;

#ifdef MRN_NEED_FREE_STRING_MEMALLOC_PLUGIN_VAR
my_free(*old_value_ptr, MYF(0));
*old_value_ptr = my_strdup(new_value, MYF(MY_WME));
#else
*old_value_ptr = (char *)new_value;
#endif

DBUG_VOID_RETURN;
}

static MYSQL_SYSVAR_STR(vector_column_delimiter, mrn_vector_column_delimiter,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_MEMALLOC,
"The vector column delimiter",
NULL,
&mrn_vector_column_delimiter_update,
" ");

static void mrn_database_path_prefix_update(THD *thd,
struct st_mysql_sys_var *var,
void *var_ptr, const void *save)
Expand Down Expand Up @@ -879,6 +904,7 @@ static struct st_mysql_sys_var *mrn_system_variables[] =
MYSQL_SYSVAR(lock_timeout),
MYSQL_SYSVAR(libgroonga_version),
MYSQL_SYSVAR(version),
MYSQL_SYSVAR(vector_column_delimiter),
NULL
};

Expand Down Expand Up @@ -10071,7 +10097,7 @@ void ha_mroonga::storage_store_fields(uchar *buf, grn_id record_id)
for (int i = 0; i * sizeof(grn_id) < value_length; i++) {
grn_id id = ids[i];
if (i > 0) {
GRN_TEXT_PUTC(ctx, &unvectored_value, ' ');
GRN_TEXT_PUTS(ctx, &unvectored_value, mrn_vector_column_delimiter);
}
char key[GRN_TABLE_MAX_KEY_SIZE];
int key_length;
Expand Down
@@ -0,0 +1,29 @@
DROP TABLE IF EXISTS document;
DROP TABLE IF EXISTS category;
CREATE TABLE category (
category CHAR(10) PRIMARY KEY
) DEFAULT CHARSET=utf8
COMMENT='default_tokenizer "TokenDelimit"';
CREATE TABLE document (
id INT NOT NULL,
title TEXT,
categories TEXT COMMENT 'flags "COLUMN_VECTOR", type "category"',
PRIMARY KEY(id)
) DEFAULT CHARSET=utf8;
SHOW GLOBAL VARIABLES LIKE 'mroonga_vector_column_delimiter';
Variable_name Value
mroonga_vector_column_delimiter
INSERT INTO document VALUES(1, "Mroonga is the fastest search engine", "it database fulltext");
SELECT id, title, categories FROM document;
id title categories
1 Mroonga is the fastest search engine IT DATABASE FULLTEXT
SET GLOBAL mroonga_vector_column_delimiter = ';';
SHOW GLOBAL VARIABLES LIKE 'mroonga_vector_column_delimiter';
Variable_name Value
mroonga_vector_column_delimiter ;
SELECT id, title, categories FROM document;
id title categories
1 Mroonga is the fastest search engine IT;DATABASE;FULLTEXT
DROP TABLE document;
DROP TABLE category;
SET GLOBAL mroonga_vector_column_delimiter = ' ';
54 changes: 54 additions & 0 deletions mysql-test/mroonga/storage/variable/t/vector_column_delimiter.test
@@ -0,0 +1,54 @@
# Copyright(C) 2014 Naoya Murakami <naoya@createfield.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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

--source include/not_embedded.inc
--source ../../../include/mroonga/have_mroonga.inc
--source ../../../include/mroonga/have_mroonga_helper.inc

--disable_warnings
DROP TABLE IF EXISTS document;
DROP TABLE IF EXISTS category;
--enable_warnings

CREATE TABLE category (
category CHAR(10) PRIMARY KEY
) DEFAULT CHARSET=utf8
COMMENT='default_tokenizer "TokenDelimit"';

CREATE TABLE document (
id INT NOT NULL,
title TEXT,
categories TEXT COMMENT 'flags "COLUMN_VECTOR", type "category"',
PRIMARY KEY(id)
) DEFAULT CHARSET=utf8;

SHOW GLOBAL VARIABLES LIKE 'mroonga_vector_column_delimiter';

INSERT INTO document VALUES(1, "Mroonga is the fastest search engine", "it database fulltext");
SELECT id, title, categories FROM document;

SET GLOBAL mroonga_vector_column_delimiter = ';';

SHOW GLOBAL VARIABLES LIKE 'mroonga_vector_column_delimiter';

SELECT id, title, categories FROM document;

DROP TABLE document;
DROP TABLE category;

SET GLOBAL mroonga_vector_column_delimiter = ' ';

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

0 comments on commit c538a7f

Please sign in to comment.