Last active
December 29, 2015 08:49
-
-
Save naoa/7645725 to your computer and use it in GitHub Desktop.
Groonga index dump
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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