HyperEstraierのRubyバインディングの実験

実験してみた。

参考:無稽筆談(2009-06-24)

#!/usr/bin/env ruby 

require "estraier"
include Estraier

class EstSearcher 
  def self.search keyword, dbpath
    db = Database::new
    db.open(dbpath, Database::DBREADER)
    cond = Condition::new
    cond.set_phrase(keyword)
    result = db.search(cond)
    resultList = []
    for i in 0...result.doc_num
      doc = db.get_doc(result.get_doc_id(i), 0)
      next unless doc
      resultList << doc
    end
    db.close
    resultList
  end
end


if __FILE__ == $0
  EstSearcher.search(ARGV[0], ARGV[1]).each do |doc|
    uri = doc.attr("@uri")
    puts("URI:" + uri) if uri
    title = doc.attr("@title")
    puts("title: " + title) if title
  end
end


$ ./est.rb キーワード casket/

簡単でとてもたすかる。