[Ferret-talk] FerretHash

David Balmain
2007-03-02T11:01:45Z

On 3/2/07, Caleb Clausen <caleb at inforadical.net>
wrote:
> Dave, thank you so much for the 0.11 release(s). You have solved many
> problems for me. As part of my appreciation for your good works, I am
> offering up for public consideration a silly little class that I wrote.
> (Code is below.) This class offers a simplified Hash-like interface to
> (a very restricted subset of) Ferret. Hence I call it FerretHash.
>
> FerretHash comes with its very own pet Ferret bug. Run the crude unit
> test to see the problem. (Long story short, it looks like term
> frequency, as reported by IndexReader#terms, does not take deletions
> into account.)

Hey Caleb,

Unfortunately it would be too inefficient to change all of the term
counts when you delete a document. What you can do is optimize the
index before you iterate over the terms. For example;

  def keys
    @writer.optimize
    reader=Ferret::Index::IndexReader.new(@name)
    result=reader.terms(:key).extend(Enumerable).map{|term,freq|
      freq==1 or fail
      term
    }
    reader.close
    return result
  end

Hope that makes sense.

--
Dave Balmain