require 'ferret' module Enid class Entry def open_index(path) @idx = Ferret::Index::Index.new(:path => path, :id_field => :id, :key => :id) end def reindex(world) raise "No index opened" unless @idx index world @idx.flush @idx.optimize end def search_ferret(query) raise "No index opened" unless @idx topdocs = @idx.search(query, :limit => 25) [topdocs.hits.map { |doc, score| @idx[doc.doc] }, topdocs.total_hits] end def index(world) world.each { |id, entry| @idx << {:id => entry.id, :body => entry.entry.to_html.gsub(/\A

|<\/p>\z/, '')} } self end end end