Carl Youngblood
2005-Dec-02 01:32 UTC
[Ferret-talk] How to get the count of matching documents
I''m trying to generate a rails pagination helper for some ferret search results, and I need to know how many total matches there are to my search query. I don''t see an obvious way of finding this. Any help would be appreciated. Thanks, Carl Youngblood
David Balmain
2005-Dec-02 02:07 UTC
[Ferret-talk] How to get the count of matching documents
Hi Carl,
This is easy. If you use the search method (not search_each) a TopDocs
object is returned which has the attribute total hits. Or you can
continue to use the search_each method like this;
total_hits = index.search_each("query") {|doc, score| puts
"doc"}
Hope this helps,
Dave
On 12/2/05, Carl Youngblood <carl at youngbloods.org>
wrote:> I''m trying to generate a rails pagination helper for some ferret
> search results, and I need to know how many total matches there are to
> my search query. I don''t see an obvious way of finding this. Any
> help would be appreciated.
>
> Thanks,
> Carl Youngblood
>
> _______________________________________________
> Ferret-talk mailing list
> Ferret-talk at rubyforge.org
> http://rubyforge.org/mailman/listinfo/ferret-talk
>
Carl Youngblood
2005-Dec-02 03:16 UTC
[Ferret-talk] How to get the count of matching documents
No doubt I just needed to scour the documentation more thoroughly, but thanks for the help. Carl On 12/1/05, David Balmain <dbalmain.ml at gmail.com> wrote:> Hi Carl, > > This is easy. If you use the search method (not search_each) a TopDocs > object is returned which has the attribute total hits. Or you can > continue to use the search_each method like this; > > total_hits = index.search_each("query") {|doc, score| puts "doc"} > > Hope this helps, > Dave
Anatol Pomozov
2005-Dec-02 08:12 UTC
[Ferret-talk] How to get the count of matching documents
What do you mean saying "more thoroughly". This is code from my
application
and it works great.
page_num = @params[''page''] ?
@params[''page''].to_i : 1
total_hits = index.search_each(query, :num_docs => PAGE_SIZE, :first_doc
=> PAGE_SIZE*(page_num-1)) do |doc_num, score|
@documents << index[doc_num]
end
@document_pages = Paginator.new self, total_hits, PAGE_SIZE, page_num
Is it makes sense to put it to "HowTos" page??
On 12/2/05, Carl Youngblood <carl at youngbloods.org>
wrote:>
> No doubt I just needed to scour the documentation more thoroughly, but
> thanks for the help.
>
> Carl
>
> On 12/1/05, David Balmain <dbalmain.ml at gmail.com> wrote:
> > Hi Carl,
> >
> > This is easy. If you use the search method (not search_each) a TopDocs
> > object is returned which has the attribute total hits. Or you can
> > continue to use the search_each method like this;
> >
> > total_hits = index.search_each("query") {|doc, score| puts
"doc"}
> >
> > Hope this helps,
> > Dave
>
> _______________________________________________
> Ferret-talk mailing list
> Ferret-talk at rubyforge.org
> http://rubyforge.org/mailman/listinfo/ferret-talk
>
--
anatol (http://pomozov.info)
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://rubyforge.org/pipermail/ferret-talk/attachments/20051202/ea6f24ec/attachment.htm
David Balmain
2005-Dec-02 15:15 UTC
[Ferret-talk] How to get the count of matching documents
On 12/2/05, Anatol Pomozov <anatol.pomozov at gmail.com> wrote:> What do you mean saying "more thoroughly". This is code from my application > and it works great. > > page_num = @params[''page''] ? @params[''page''].to_i : 1 > > total_hits = index.search_each(query, :num_docs => PAGE_SIZE, :first_doc > => PAGE_SIZE*(page_num-1)) do |doc_num, score| > @documents << index[doc_num] > end > > @document_pages = Paginator.new self, total_hits, PAGE_SIZE, page_num > > Is it makes sense to put it to "HowTos" page??Very good idea. I''ve had a few people ask me about this. I wish I had time. I''m leaving the Wiki up to the users at this stage. When I finish cFerret I''ll have more time. Dave