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