http://internet.kill.jp/wiki/index.php?%B5%BB%BD%D1%2FGoogle%2F%A5%EF%A5%A4%A5%EB%A5%C9%A5%AB%A1%BC%A5%C9%B7%EF%BF%F4%BC%E8%C6%C0をちょっと改造

文字セットを複数箇所指定できるようにしてみた。ツン[タ-ド][ラ-ロ] とすると、ツンタラ、ツンタリ……ツンドレ、ツンドロ の Google ヒット件数を取得できます。

#! ruby -Ke

require "iconv"
require 'cgi'
require 'net/http'

class GoogleSearch
  def initialize (config = {})
    @service_host = "www.google.com"
  end

  def search(key)
    query = CGI.escape(key)
    Net::HTTP.start(@service_host, 80) {|http|
      response = http.get2("/search?q=#{query}&ie=UTF-8&oe=UTF-8")
      if m = /\bswrnum=(\d+)\b/.match(response.body)
        return count = m[1].to_i
      end
    }
    return nil
  end
end

g = GoogleSearch.new
conv = Iconv.new("UTF-8","EUC-JP")

def gentermlist(str)
  if str =~ /^(.*?)\[(.)\-(.)\](.*?)$/
    pre, c, ec, after = $1, $2, $3, $4
    lis=[]
    (c..ec).each{|char|
      gentermlist(after).each{|postterm|
        lis.push "#{pre}#{char}#{postterm}"
      }
    }
    lis
  else
    [str]
  end
end

while line = gets
  gentermlist(line).each do |key|
    key_toconv = key.clone

    count = g.search(conv.iconv(key_toconv))

    puts "#{key} #{count}"

    STDERR.print '.'
  end
end