acts_as_searchableを使う程度であれば、例えばDebianなら、 aptでhyperestraierのパッケージを入れるだけで十分なのですが、 estcmd等のコマンドラインツールを使ったりしようとすると、 estraier というRubyGemsが必要になったりします。

   1  # estcmd
   2  /usr/local/lib/ruby/site_ruby/1.8/rubygems.rb:304:in `report_activate_error': Could not find RubyGem estraier (> 0) (Gem::LoadError)
   3          from /usr/local/lib/ruby/site_ruby/1.8/rubygems.rb:238:in `activate'
   4          from /usr/local/lib/ruby/site_ruby/1.8/rubygems.rb:76:in `active_gem_with_options'
   5          from /usr/local/lib/ruby/site_ruby/1.8/rubygems.rb:50:in `gem'
   6          from /usr/local/bin/estcmd:15

このestraierをインストールするためには、HyperEstraier のパッケージ以外にも、 QDBM の開発用ライブラリパッケージを インストールしておく必要があります。

   1  # aptitude install libqdbm-dev

あとは、gemコマンドで通常通りにestraierをインストールします。

   1  # gem install estraier

これで estcmd などのコマンドラインツールが使えるようになります。

   1  # estcmd
   2  estcmd: command line utility for the core API of Hyper Estraier
   3  
   4  usage:
   5    estcmd put [-cl] [-ws] db [file]
   6    estcmd out [-cl] db expr
   7    estcmd edit db expr name [value]
   8    estcmd get db expr [attr]
   9    estcmd uriid db uri
  10    estcmd inform db
  11    estcmd optimize [-onp] [-ond] db
  12    estcmd merge [-cl] db target
  13    estcmd search [-vu|-va|-vf|-vs] [-gs|-gf|-ga] [-cd] [-ni] [-sf|-sfr|-sfu|-sfi] [-attr expr] [-ord expr] [-max num] [-sk num] [-aux num] [-dis name] db [phrase]

posted by Png genki on Fri 7 Dec 2007 at 18:08

Changeset 8321 - Rails Trac - Trac

Preparing for release shortly

Tracのタイムラインを見ていたら、Rails 2.0が本日 (米国時間だと12/6)リリースするみたいですね。

rails_2_0

posted by Png genki on Fri 7 Dec 2007 at 08:52

ワークパイル(Work pile)は、並列処理の為のアルゴリズムの一種です。

lucille 開発日記: マルチスレッド化: ワークパイル

簡単に云ってしまえば、ワークパイルはサーバ/クライアント機構と似たようなもので、ジョブを処理するスレッド部分ではマスタースレッドから仕事(ジョブ)を受け取って処理し、仕事がなくなるまでループするというものです。

いわゆる生産者消費者問題を解決する手法の一つですね。 ちょっとサンプルコードを見てもらったほうがはやいかも。

workpile.rb

   1  require 'thread'
   2  
   3  class Workpile
   4    def initialize(num_workers)
   5      @queue = Queue.new
   6      @workers = ThreadGroup.new
   7  
   8      # Spawn worker threads
   9      num_workers.times do |i|
  10        @workers.add(Thread.new do
  11          puts "Worker #%d is ready." % i
  12          loop do
  13            @queue.pop.call # work
  14            puts " (#%d)" % i
  15          end
  16        end)
  17      end
  18    end
  19  
  20    def push_task(&block)
  21      @queue.push block
  22      @workers.list.sort_by{rand}.each{|worker| worker.run} # wake up!
  23    end
  24  
  25    def start
  26      while input = gets.chomp
  27        break if input == 'exit'
  28        input.split('').each do |i|
  29          push_task{print i}
  30        end
  31      end
  32    end
  33  end
  34  
  35  Workpile.new(3).start

出力結果

   1  % ruby workpile.rb
   2  Worker #0 is ready.
   3  Worker #1 is ready.
   4  Worker #2 is ready.
   5  hello!
   6  h (#0)
   7  e (#2)
   8  l (#1)
   9  l (#0)
  10  o (#2)
  11  ! (#0)

3つのワーカースレッドを作成して、投入したタスクを処理しています。 RubyのQueueは同期の面倒を見てくれるので、何も考えずにpushpopでタスクのやり取りを行うことができてしまいます。 しかも、キューが空になったらカレントスレッドを停止するように なってるんですね。

並列処理というとC/C++でCriticalSectionやmutexのネイティブAPIを さわるようなのばかりだったので、こんなに簡潔に記述できるのは 良いですね。やはりインターフェイス重要だな。

クリスマスに出る(という噂の)Ruby 1.9でネイティブスレッド化されたら、 もっと楽しいかもしれませんねー。

posted by Png genki on Fri 7 Dec 2007 at 06:14

ちょっと使ってみて良い感じだったので紹介します。

Rak

Rak is a grep replacement in pure Ruby. It accepts Ruby syntax regular expressions and automatically recurses directories, skipping .svn/, .cvs/, pkg/ and more things you don't care about. It is based on the Perl tool ack by Andy Lester.

Pure ruby で書かれた grep みたいな感じですね。 なんといっても見た目が美しい。

rak_demo

デフォルトで再帰的に、.svn や .cvs を無視して検索してくれる というのも良い感じ。

RubyGemsとして提供されているので、インストールするのは

   1  % sudo gem install rak

でOKです。

See Also

更新履歴

  • [2007/12/5 23:08] ackへのポインタを追加。
  • [2007/12/26] ソケットファイルがある場合の問題への対処法の紹介
posted by Png genki on Wed 5 Dec 2007 at 20:40

昨年 に続いて今年も、 東京と関東のRubyの忘年会2007 が行われるようです。

Rubyistの皆さん、今年も一年間お疲れさまでした。

RubyKaigi2007での感動的スピーチがまだまだ記憶に新しい今日この頃ですが、早いもので師走を迎え、今年も残すところあと一ヶ月となりました。

ということで、今年の振り返りと来年に向けた英気を養う場として忘年会を行いたいと思います。皆様お誘い合わせのうえ、年忘れ出来る人も出来ない人も(出来ないけど忘れたい人も)奮ってご参加くださいませ。

早速参加申請。もろはしさん、幹事お疲れ様です。

posted by Png genki on Mon 3 Dec 2007 at 12:27

RaPT は、Ruby on Railsのプラグインを管理するためのツールです。

RaPT is a replacement for the plugin script included with the Rails distribution. It's a little more fault-tolerant and featured than the default plugin script. The main additional feature is the ability to search for Rails plugins from the command line.

なんとなく、名前がdebianのaptに似てると思うのは僕だけでしょうか。

以前から、RailsプラグインにもRubyGemsに相当するような パッケージ管理ツールがほしいと思っていたのですが、 これを使えば目的を達することができるかも。

インストール

RaPT自体はRubyGemsとして提供されています。

   1  % sudo gem install rapt

おなじみのコマンドですね。これでOK。

使い方

   1  % rapt -h
   2  Usage: rapt [OPTIONS] command
   3  Rails plugin manager.
   4  
   5  GENERAL OPTIONS
   6    -r, --root=DIR          Set an explicit rails app directory.
   7                            Default: /home/takiuchi/blog
   8    -s, --source=URL1,URL2  Use the specified plugin repositories instead
   9   of the defaults.
  10    -v, --verbose           Turn on verbose output.
  11    -h, --help              Show this help message.

サブコマンド

   1  discover       Discover plugin repositories.
   2  list           List available plugins.
   3  search         Search for available plugins.
   4  about          Show basic info about a plugin.
   5  install        Install plugin(s) from known repositories or URLs.
   6  update         Update installed plugins.
   7  remove         Uninstall plugins.
   8  source         Add a plugin source repository.
   9  unsource       Remove a plugin repository.
  10  sources        List currently configured plugin repositories.
  11  pack:install   Install plugins from plugin pack file or URL
  12  pack:uninstall Uninstall plugins from plugin pack file or URL
  13  pack:about     Display plugin pack information

使用例

長くなったので、 Click to toggle display Example.

Install a plugin:

   1  % rapt install continuous_builder

Install a plugin from a subversion URL:

   1  % rapt install http://dev.rubyonrails.com/svn/rails/plugins/continuous_builder

Install a plugin and add a svn:externals entry to vendor/plugins

   1  % rapt install -x continuous_builder

Show information about the acts_as_chunky_bacon plugin:

   1  % rapt about acts_as_chunky_bacon

List all available plugins:

   1  % rapt list

List plugins in the specified repository:

   1  % rapt list --source=http://dev.rubyonrails.com/svn/rails/plugins/

Search available plugins:

   1  % rapt search "authentication"

Discover and prompt to add new repositories:

   1  % rapt discover

Discover new repositories but just list them, don't add anything:

   1  % rapt discover -l

Add a new repository to the source list:

   1  % rapt source http://dev.rubyonrails.com/svn/rails/plugins/

Remove a repository from the source list:

   1  rapt unsource http://dev.rubyonrails.com/svn/rails/plugins/

Show currently configured repositories:

   1  % rapt sources

Show the options for the list command:

   1  % rapt list -h

Install a plugin pack:

   1  % rapt pack:install http://opensource.agileevolved.com/pluginpacks/standard.pluginpack

View plugin pack meta data:

   1  % rapt pack:about http://opensource.agileevolved.com/pluginpacks/standard.pluginpack

posted by Png genki on Sun 2 Dec 2007 at 03:03

Creating OpenSearch plugins for Firefox を参考に、このブログの検索機能をOpenSearchプラグインに対応しました。

FirefoxやFlock、CaminoなどのMozilla系のブラウザの検索バーから、 サイト内を検索することができます。

posted by Png genki on Sun 2 Dec 2007 at 00:38

aptitude update したらこんなエラーメッセージが出たので、対処法をメモ。

/etc/apt/apt.conf.d/70debconf

   1  APT::Cache-Limit 100000000;

後は普通に aptitude update でOK。

posted by Png genki on Sat 1 Dec 2007 at 00:15
30th Fri

Rails 2.0 RC2

Rails 2.0のRC2がリリースされましたね。正式リリースも間近のようです。

Rails 2.0: Release Candidate 2

After another batch of fixes, tweaks, and buckets of polish, we’ve prepared the hopefully last step before 2.0 can go final: Release Candidate 2. If nothing major pops up, expect the final version to land within the next week or two at the most.

早速、このブログもRails 2.0 RC2にアップデートしてみました。 今まではRC1でしたが、特に問題も無く、すんなりと移行できました。

posted by Png genki on Fri 30 Nov 2007 at 07:07

acts_as_searchable is one of the most useful plugins which's enabling us to add a fulltext search feature to our models/resources easily.

Unfortunately, it is lacking an interface to the features of searching by similarity provided by HyperEstraier.

So I wrote some codes to add an interface to exploit it. This is acts_as_searchable_with_similarity.

How to use?

Here is an example.

app/models/article.rb

   1  class Article < ActiveRecord::Base
   2    acts_as_searchable
   3  end
   4  
   5  Article.similarity_search(target_article,  :limit => 5)

posted by Png genki on Thu 29 Nov 2007 at 23:37