Brian's Waste of Time

Sat, 22 Oct 2005

Ferret!

David Balmain has released Ferret unto the world. Ferret is one of the most requested libraries I have seen for ruby -- a native port (not a gcj and bindings!) of Lucene!

#!/usr/bin/env ruby
require 'rubygems'
require 'ferret'
require 'find'
include Ferret

# index = Index::Index.new(:path => '/tmp/ferret-test')
index = Index::Index.new(:default_field => 'content')

Find.find("/Users/brianm/blosxom/entries/src/") do |path|
  if FileTest.file? path 
    File.open(path) do |file|
      index.add_document :file => path, 
                         :content => file.readlines
    end
  end
end

index.search_each("Lucene") do |doc, score| 
  puts index[doc]['file']
end

Yields:

brianm@kite:~$ ./ferret_test.rb 
/Users/brianm/blosxom/entries/src/java/ojb/lucene-ojb.txt
/Users/brianm/blosxom/entries/src/ruby/#ferret.txt#
/Users/brianm/blosxom/entries/src/java/spring-lucene.txt
/Users/brianm/blosxom/entries/src/java/lucene-graphs.txt
/Users/brianm/blosxom/entries/src/ruby/gcj-osx.txt
/Users/brianm/blosxom/entries/src/ruby/codefest-grant.txt
/Users/brianm/blosxom/entries/src/reseach-solipsysm.txt
/Users/brianm/blosxom/entries/src/java/rails-for-strutters.txt
brianm@kite:~$  

Yea! Now to get David Black to send him my grant...

0 writebacks [/src/ruby] permanent link