Sorting Search results


#1

I tried sorting the search results in Ferret::Index::Index#search and
what I found was that the sort is applied not to the whole search but to
the returned results.

Suppose I have these results:

Text - Num

foo - 2
bar - 3
far - 4
boo - 1

If I limit the search to the first two and sort by num I get:

foo - 2
bar - 3

while I think the natural behaviour would be:

boo - 1
foo - 2

Is this intended or a bug?

Greetings,

Pedro.


#2

Thanks Pedro,

This was a bug. It is now fixed.

Regards,
Dave


#3

On Tue, 2006-04-25 at 22:20 +0900, David B. wrote:

Thanks Pedro,

This was a bug. It is now fixed.

I think I can still see it in my search results. Are you sure it’s
fixed? I’m using SVN now.

Greetings,

Pedro.


#4

It’s working here;
require ‘ferret’
include Ferret
include Ferret::Index
i = Index.new
i << {:a => “one”, :b => 1}
i << {:a => “two two”, :b => 2}
i << {:a => “three three three”, :b => 3}
i << {:a => “four”, :b => 4}

i.search_each("one two three four") do |d, s|
  puts "#{s} => #{i[d]}"
end
# 0.0612355209887028 => Document {
#   stored/uncompressed,indexed,tokenized,<b:1>
#   stored/uncompressed,indexed,tokenized,<a:one>
# }
# 0.0612355209887028 => Document {
#   stored/uncompressed,indexed,tokenized,<b:4>
#   stored/uncompressed,indexed,tokenized,<a:four>
# }
# 0.0541250631213188 => Document {
#   stored/uncompressed,indexed,tokenized,<b:2>
#   stored/uncompressed,indexed,tokenized,<a:two two>
# }
# 0.0530315153300762 => Document {
#   stored/uncompressed,indexed,tokenized,<b:3>
#   stored/uncompressed,indexed,tokenized,<a:three three three>
# }

i.search_each("one two three four", :sort => :b) do |d, s|
  puts "#{s} => #{i[d]}"
end
# 0.0612355209887028 => Document {
#   stored/uncompressed,indexed,tokenized,<b:1>
#   stored/uncompressed,indexed,tokenized,<a:one>
# }
# 0.0541250631213188 => Document {
#   stored/uncompressed,indexed,tokenized,<b:2>
#   stored/uncompressed,indexed,tokenized,<a:two two>
# }
# 0.0530315153300762 => Document {
#   stored/uncompressed,indexed,tokenized,<b:3>
#   stored/uncompressed,indexed,tokenized,<a:three three three>
# }
# 0.0612355209887028 => Document {
#   stored/uncompressed,indexed,tokenized,<b:4>
#   stored/uncompressed,indexed,tokenized,<a:four>
# }

i.search_each("one two three four",
              {:sort => :b, :first_doc => 1, :num_docs => 2}) do |d, 

s|
puts “#{s} => #{i[d]}”
end
# 0.0541250631213188 => Document {
# stored/uncompressed,indexed,tokenized,<b:2>
# stored/uncompressed,indexed,tokenized,<a:two two>
# }
# 0.0530315153300762 => Document {
# stored/uncompressed,indexed,tokenized,<b:3>
# stored/uncompressed,indexed,tokenized,<a:three three three>
# }