Class | Ferret::Index::TermDocEnum |
In: |
ext/r_index.c
|
Parent: | Object |
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.
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
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
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.