require "rubygems" require "ferret" include Ferret include Ferret::Index index = Index.new() index << { :title => "a matching document", :age => 100} index << { :title => "another matching document", :age => 2} index.optimize filter_proc = lambda do |doc_id, score, searcher| age = searcher[doc_id][:age].to_i 1.0/age end # Output: # | max_score: 0.0615548193454742 # | 0 => 0.061555: a matching document # | 1 => 0.049244: another matching document # Expected: # | doc0 gets a scale of 0.01 from filter_proc, # | doc1 gets 0.5 # | Why is the second document not first in resultlist? puts "Test 1" docs = index.search("matching", :filter_proc => filter_proc) puts "max_score: " + docs.max_score.to_s docs.hits.each { |hit| puts "%i => %f: %s" % [hit.doc, hit.score, index[hit.doc][:title]] } simple_proc = lambda do |doc_id, score, searcher| true end # Output: # | max_score: 0.0 # | 1 => 0.000000: another matching document # Expected: # | score|max_score > 0 # | This works when removing the filter_proc or the "+" before the "age:2" puts "Test 2" docs = index.search("+matching +age:2", :filter_proc => simple_proc) puts "max_score: " + docs.max_score.to_s docs.hits.each { |hit| puts "%i => %f: %s" % [hit.doc, hit.score, index[hit.doc][:title]] }