Bye Bye Moore

PoCソルジャーな零細事業主が作業メモを残すブログ

監視レスな検索エンジンDuckDuckGoをRuby経由で使う

DuckDuckGoプライバシー重視なオープンソース検索エンジンです。
Emacs Wikiなんかでは標準の検索エンジンになっていますね。
利用ユーザの情報を保存しないため、高い安全性を誇ります。
原理上はAさんとBさんが同じ検索ワードで検索をかけても同じ結果がでます。*1

ruby gem

さて、この素晴しい検索エンジンRubyで使う方法が用意されています。

$ gem install duck-duck-go

試しに、「Rubyのパパ」こと、まつもゆきひろ氏を調べてみます。

require 'duck_duck_go'

result = DuckDuckGo.new.zeroclickinfo("Yukihiro Matsumoto")
=> #<DuckDuckGo::ZeroClickInfo:0x007f88258c3ef8
 @abstract=
  "Yukihiro Matsumoto is a Japanese computer scientist and software programmer best known as the chief designer of the Ruby programming language and its reference implementation, Matz's Ruby Interpreter. His demeanor has brought about a motto in the Ruby community \"Matz is nice and so we are nice,\" commonly abbreviated as MINASWAN.",
...

検索結果を確認するには以下のようにします

result.heading
=> "Yukihiro Matsumoto"

result.abstract_text
=> "Yukihiro Matsumoto is a Japanese computer scientist and software programmer best known as the chief designer of the Ruby programming language and its reference implementation, Matz's Ruby Interpreter. His demeanor has brought about a motto in the Ruby community \"Matz is nice and so we are nice,\" commonly abbreviated as MINASWAN."

"Zero Click Info API"という、手早く検索するためのAPIに則った形になっています。

*1:実際にはアップデートやら何やらで多少ズレるでしょうが