Skip to content

Instantly share code, notes, and snippets.

@naoa
Last active December 29, 2015 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naoa/7645725 to your computer and use it in GitHub Desktop.
Save naoa/7645725 to your computer and use it in GitHub Desktop.
Groonga index dump
require "groonga"
database_path = ARGV[0]
ft_index = ARGV[1]
output_file = ARGV[2]
Groonga::Database.open(database_path)
index_column_name = "#{ft_index}.index"
index = Groonga[index_column_name]
index.table.open_cursor do |table_cursor|
index.open_cursor(table_cursor) do |cursor|
current_term_id = nil
before_token = nil
token_cnt = 1
cursor.each do |posting|
current_term_id ||= posting.term_id
if current_term_id == posting.term_id
token_cnt +=1
else
if output_file != nil
io = File.open(output_file, "a")
io.puts "#{before_token},#{token_cnt}"
io.close
else
puts "#{before_token},#{token_cnt}"
end
token_cnt = 1
current_term_id = posting.term_id
end
before_token = posting.term.key
end
unless before_token == nil
if output_file != nil
io = File.open(output_file, "a")
io.puts "#{before_token},#{token_cnt}"
io.close
else
puts "#{before_token},#{token_cnt}"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment