Object
TermVectors are most commonly used for creating search result excerpts and highlight search matches in results. This is all done internally so you won’t need to worry about the TermVector object. There are some other reasons you may want to use the TermVectors object however. For example, you may wish to see which terms are the most commonly occurring terms in a document to implement a MoreLikeThis search.
tv = index_reader.term_vector(doc_id, :content) tv_term = tv.find {|tvt| tvt.term = "fox"} # get the term frequency term_freq = tv_term.positions.size # get the offsets for a term offsets = tv_term.positions.collect {|pos| tv.offsets[pos]}
positions and offsets can be nil depending on what you set the :term_vector to when you set the FieldInfo object for the field. Note in particular that you need to store both positions and offsets if you want to associate offsets with particular terms.
TermVectors are most commonly used for creating search result excerpts and highlight search matches in results. This is all done internally so you won’t need to worry about the TermVector object. There are some other reasons you may want to use the TermVectors object however. For example, you may wish to see which terms are the most commonly occurring terms in a document to implement a MoreLikeThis search.
tv = index_reader.term_vector(doc_id, :content) tv_term = tv.find {|tvt| tvt.term = "fox"} # get the term frequency term_freq = tv_term.positions.size # get the offsets for a term offsets = tv_term.positions.collect {|pos| tv.offsets[pos]}
positions and offsets can be nil depending on what you set the :term_vector to when you set the FieldInfo object for the field. Note in particular that you need to store both positions and offsets if you want to associate offsets with particular terms.
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.