Class Ferret::Index::TermEnum
In: ext/r_index.c
Parent: Object

Summary

The TermEnum object is used to iterate through the terms in a field. To get a TermEnum you need to use the IndexReader#terms(field) method.

Example

  te = index_reader.terms(:content)

  te.each {|term, doc_freq| puts "#{term} occurred #{doc_freq} times" }

  # or you could do it like this;
  te = index_reader.terms(:content)

  while te.next?
    puts "#{te.term} occured in #{te.doc_freq} documents in the index"
  end

Methods

doc_freq   each   field=   next?   set_field   skip_to   term   to_json  

Public Instance methods

Returns the document frequency of the current term pointed to by the enum. That is the number of documents that this term appears in. The method should only be called after a successful call to TermEnum#next.

Iterates through all the terms in the field, yielding the term and the document frequency.

Set the field for the term_enum. The field value should be a symbol as usual. For example, to scan all title terms you‘d do this;

  term_enum.set_field(:title).each do |term, doc_freq|
    do_something()
  end

Returns the next term in the enumeration or nil otherwise.

Set the field for the term_enum. The field value should be a symbol as usual. For example, to scan all title terms you‘d do this;

  term_enum.set_field(:title).each do |term, doc_freq|
    do_something()
  end

Skip to term target. This method can skip forwards or backwards. If you want to skip back to the start, pass the empty string "". That is;

  term_enum.skip_to("")

Returns the first term greater than or equal to target

Returns the current term pointed to by the enum. This method should only be called after a successful call to TermEnum#next.

Returns a JSON representation of the term enum. You can speed this up by having the method return arrays instead of objects, simply by passing an argument to the to_json method. For example;

  term_enum.to_json() #=>
  # [
  #   {"term":"apple","frequency":12},
  #   {"term":"banana","frequency":2},
  #   {"term":"cantaloupe","frequency":12}
  # ]

  term_enum.to_json(:fast) #=>
  # [
  #   ["apple",12],
  #   ["banana",2],
  #   ["cantaloupe",12]
  # ]

[Validate]