Forum: Ferret search_each returns partial 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.
Vamsee K. (Guest)
on 2006-01-10 09:23
(Received via mailing list)
Hi,

I'm having some trouble with ferret search_each. I'm posting rails'
script/console output, so I guess you can decrypt it:

 >> res = []
=> []
 >> index.search_each('name: a*') do |doc, score|
?> res << doc
 >> end
=> 50
 >> res.size
=> 10
 >>

I'm guessing the '=>50' after search_each indicates that there are 50
documents returned. How come I can only see 10 in the array res?

Thanks much,
Vamsee.
Finn S. (Guest)
on 2006-01-10 17:38
(Received via mailing list)
On 1/10/06, Vamsee K. <removed_email_address@domain.invalid> wrote:
> I'm guessing the '=>50' after search_each indicates that there are 50 documents 
returned. How come I can only see 10 in the array res?

If you look at Index::Index's search_each method you'll see it calls
do_search internally, which in turn calls Search::IndexSearcher's
search method. This search method takes an options hash which accepts
the following keys:

    # filter::    filters docs from the search result
    # first_doc:: The index in the results of the first doc retrieved.
    #             Default is 0
    # num_docs::  The number of results returned. Default is 10
    # sort::      An array of SortFields describing how to sort the
results.

So it is returning 10 docs due to the fact that num_docs defaults to 10.

I've been waiting for David to return to bring this up again, but I
think this code should be moved out of Search::IndexSearcher into
Index::Index and that there should be a Hits class a la Java Lucene to
manage the hits returned.

-F
This topic is locked and can not be replied to.