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

Summary

Use a TermDocEnum to iterate through the documents that contain a particular term. You can also iterate through the positions which the term occurs in a document.

Example

  tde = index_reader.term_docs_for(:content, "fox")

  tde.each do |doc_id, freq|
    puts "fox appeared #{freq} times in document #{doc_id}:"
    positions = []
    tde.each_position {|pos| positions << pos}
    puts "  #{positions.join(', ')}"
  end

  # or you can do it like this;
  tde.seek(:title, "red")
  while tde.next?
    puts "red appeared #{tde.freq} times in document #{tde.doc}:"
    positions = []
    while pos = tde.next_position
      positions << pos
    end
    puts "  #{positions.join(', ')}"
  end

Methods

doc   each   each_position   freq   next?   next_position   seek   seek_term_enum   skip_to  

Public Instance methods

Returns the current document number pointed to by the term_doc_enum.

Iterate through the documents and document frequencies in the term_doc_enum.

NOTE: this method can only be called once after each seek. If you need to call +each+ again then you should call +seek+ again too.

Iterate through each of the positions occupied by the current term in the current document. This can only be called once per document. It can be used within the each method. For example, to print the terms documents and positions;

  tde.each do |doc_id, freq|
    puts "term appeared #{freq} times in document #{doc_id}:"
    positions = []
    tde.each_position {|pos| positions << pos}
    puts "  #{positions.join(', ')}"
  end

Returns the frequency of the current document pointed to by the term_doc_enum.

Move forward to the next document in the enumeration. Returns true if there is another document or false otherwise.

Move forward to the next document in the enumeration. Returns true if there is another document or false otherwise.

Seek the term term in the index for field. After you call this method you can call next or each to skip through the documents and positions of this particular term.

Seek the current term in term_enum. You could just use the standard seek method like this;

  term_doc_enum.seek(term_enum.term)

However the seek_term_enum method saves an index lookup so should offer a large performance improvement.

Skip to the required document number target and return true if there is a document >= target.

[Validate]