Skip to content

Commit

Permalink
out: add WITH_POSITION index flags automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Nov 20, 2014
1 parent f00b8d0 commit 8075106
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
44 changes: 32 additions & 12 deletions lib/fluent/plugin/out_groonga.rb
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def initialize(client, table_name, mappings)
@client = client
@table_name = table_name
@mappings = mappings
@table = nil
@taget_table = nil
@columns = nil
end

Expand All @@ -311,19 +311,24 @@ def update(records)

private
def ensure_table
return if @table
return if @target_table

table_list = @client.execute("table_list")
target_table = table_list.find do |table|
table.name == @table_name
@tables = {}
@client.execute("table_list").collect do |table|
name = table.name
options = {
:default_tokenizer => table.default_tokenizer,
}
@tables[name] = Table.new(table.name, options)
end
if target_table
@table = Table.new(@table_name, target_table.domain)
else

@target_table = @tables[@table_name]
unless @target_table
@client.execute("table_create",
"name" => @table_name,
"flags" => "TABLE_NO_KEY")
@table = Table.new(@table_name, nil)
@target_table = Table.new(@table_name)
@tables[@table_name] = @target_table
end
end

Expand Down Expand Up @@ -362,7 +367,10 @@ def create_column(name, sample_values)
"type" => value_type)
if mapping
mapping.indexes.each do |index|
index_flags = ["COLUMN_INDEX", index[:flags]].compact
index_flags = ["COLUMN_INDEX"]
table = @tables[index[:table]]
index_flags << "WITH_POSITION" if table and table.default_tokenizer
index_flags << index[:flags] if index[:flags]
@client.execute("column_create",
"table" => index[:table],
"name" => index[:name],
Expand Down Expand Up @@ -491,9 +499,21 @@ def long_text_values?
end

class Table
def initialize(name, key_type)
attr_reader :name
attr_reader :flags
attr_reader :domain
attr_reader :range
attr_reader :default_tokenizer
attr_reader :normalizer
attr_reader :token_filters
def initialize(name, options={})
@name = name
@key_type = key_type
@flags = options[:flags]
@domain = options[:domain]
@range = options[:range]
@default_tokenizer = options[:default_tokenizer]
@normalizer = options[:normalizer]
@token_filters = options[:token_filters]
end
end

Expand Down
1 change: 0 additions & 1 deletion sample/store-apache.conf
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@
<index>
table Terms
name logs_message_index
flags WITH_POSITION
</index>
</mapping>

Expand Down
1 change: 0 additions & 1 deletion sample/store-syslog.conf
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
<index>
table Terms
name logs_message_index
flags WITH_POSITION
</index>
</mapping>
</match>

0 comments on commit 8075106

Please sign in to comment.