molten-trunk/molten5_withgrid/vendor/plugins/acts_as_ferret/lib/more_like_this.rb
# create an ordered(by score) list of word,fieldname,score 
# structures
create an ordered(by score) list of word,fieldname,score
structures
create an ordered ( by score ) list of word fieldname score structures
def create_queue(term_freq_map, reader, options)
          pq = Array.new(term_freq_map.size)
          similarity = options[:similarity]
          num_docs = reader.num_docs
          term_freq_map.each_pair do |word, tf|
            next if options[:min_term_freq] && tf < options[:min_term_freq]
            top_field = options[:field_names].first
            doc_freq = 0
            options[:field_names].each do |field_name| 
              freq = reader.doc_freq(field_name, word)
              if freq > doc_freq 
                top_field = field_name
                doc_freq = freq
              end
            end
            next if options[:min_doc_freq] && doc_freq < options[:min_doc_freq]
            next if doc_freq == 0 
            idf = similarity.idf(doc_freq, num_docs)
            score = tf * idf
            pq << FrequencyQueueItem.new(word, top_field, score)
          end
          pq.compact!
          pq.sort! { |a,b| a.score<=>b.score }
          return pq
        end
def create_queue ( term_freq_map , reader , options ) pq = Array . new ( term_freq_map . size ) similarity = options [ :similarity ] num_docs = reader . num_docs term_freq_map . each_pair do | word , tf | next if options [ :min_term_freq ] && tf < options [ :min_term_freq ] top_field = options [ :field_names ] . first doc_freq = 0 options [ :field_names ] . each do | field_name | freq = reader . doc_freq ( field_name , word ) if freq > doc_freq top_field = field_name doc_freq = freq end end next if options [ :min_doc_freq ] && doc_freq < options [ :min_doc_freq ] next if doc_freq == 0 idf = similarity . idf ( doc_freq , num_docs ) score = tf * idf pq << FrequencyQueueItem . new ( word , top_field , score ) end pq . compact! pq . sort! { | a , b | a . score <=> b . score } return pq end
create an ordered(by score) list of word,fieldname,score
structures
create an ordered ( by score ) list of word fieldname score structures
# filter out words that don't occur enough times in the source # go through all the fields and find the largest document frequency # filter out words that don't occur in enough docs # index update problem ?
term_freq_map
reader
options