/ Published in: Ruby
This is a simple example for building a search index with the Ferret library (based upon http://kasparov.skife.org/blog/src/ruby/ferret.html).
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
require 'rubygems' require 'ferret' require 'find' include Ferret index = Index::Index.new(:default_field => 'content', :path => '/tmp/index_folder') ini = Time.now numFiles=0 IndexedExts=['.java','.properties'] Find.find('/code/to/index') do |path| if(IndexedExts.find {|ext| path.include?(ext)}==nil) next end puts "Indexing: #{path}" numFiles=numFiles+1 if FileTest.file? path File.open(path) do |file| index.add_document(:file => path, :content => file.readlines) end end end elapsed = Time.now - ini puts "Files: #{numFiles}" puts "Elapsed time: #{elapsed} secs\n"