Forum: Ferret Sorting Search results

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Pedro =?ISO-8859-1?Q?C=F4rte-Real?= (Guest)
on 2006-04-21 18:54
(Received via mailing list)
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.
David B. (Guest)
on 2006-04-25 17:20
(Received via mailing list)
Thanks Pedro,

This was a bug. It is now fixed.

Regards,
Dave
Pedro =?ISO-8859-1?Q?C=F4rte-Real?= (Guest)
on 2006-05-09 14:08
(Received via mailing list)
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.
David B. (Guest)
on 2006-05-09 15:32
(Received via mailing list)
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>
    # }
This topic is locked and can not be replied to.