Hi David again. I would say that Ferret works great with Rails. And now I am trying to create pagination. Because site could have millions of documents I need to create on page link something like "Page #100". Rather usual situation. But to create this links I need to know how many documents Ferret found in index. For now I am doing it with following code index = FerretConfig::INDEX index_size = index.search(query).size @document_pages = Paginator.new self, index_size, PAGE_SIZE, page_num But I am not sure that statement index.search(query).size will be effective here. Because it returns an array of found documents. What if such documents will be 100000?? I don''t want to select all this documents, just to know how many found, and then select for example 10 of them index.search_each(query, :num_docs=>PAGE_SIZE, :first_doc=>PAGE_SIZE*(page_num-1)) do |doc_num, score| @documents << index[doc_num] end So quesition is: what is the most effective way to calculate (just calculate) number of found documents? -- anatol (http://pomozov.info) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/ferret-talk/attachments/20051126/af356487/attachment.htm
On 11/26/05, Anatol Pomozov <anatol.pomozov at gmail.com> wrote:> Hi David again. > > I would say that Ferret works great with Rails. > > And now I am trying to create pagination. Because site could have millions > of documents I need to create on page link something like > "Page #100". Rather usual situation. > > But to create this links I need to know how many documents Ferret found in > index. > For now I am doing it with following code > > index = FerretConfig::INDEX > index_size = index.search(query).size > @document_pages = Paginator.new self, index_size, PAGE_SIZE, page_numActually,> index_size = index.search(query).sizewill return the number of hits in the result set which will be at most :num_docs which defaults to 10. You would need to set set num_docs to 10000 if you wanted to get 10000 results back. What you want is something like this; result_set = index.search(query, :num_docs => 20) puts result_set.size # => 20 puts result_set.total_hits # => 293487 So total hits could be 10000000 but the number of results will still only be the top 10 or whatever you set :num_docs to. If you really want, you could set :num_docs to 1. You could also use search_each like this; total_hits = index.search_each(query) do |doc_num, score| @documents << index[doc_num] end Hope that helps, Dave> But I am not sure that statement index.search(query).size will be effective > here. Because it returns an array of found documents. What if such documents > will be 100000?? I don''t want to select all this documents, just to know how > many found, and then select for example 10 of them > > index.search_each(query, :num_docs=>PAGE_SIZE, > :first_doc=>PAGE_SIZE*(page_num-1)) do |doc_num, score| > @documents << index[doc_num] > end > > So quesition is: what is the most effective way to calculate (just > calculate) number of found documents? > > -- > anatol (http://pomozov.info) > _______________________________________________ > Ferret-talk mailing list > Ferret-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/ferret-talk > > >
On 11/26/05, David Balmain <dbalmain.ml at gmail.com> wrote:> > On 11/26/05, Anatol Pomozov <anatol.pomozov at gmail.com> wrote: > > Hi David again. > > > > I would say that Ferret works great with Rails. > > > > And now I am trying to create pagination. Because site could have > millions > > of documents I need to create on page link something like > > "Page #100". Rather usual situation. > > > > But to create this links I need to know how many documents Ferret found > in > > index. > > For now I am doing it with following code > > > > index = FerretConfig::INDEX > > index_size = index.search(query).size > > @document_pages = Paginator.new self, index_size, PAGE_SIZE, > page_num > > Actually, > > > index_size = index.search(query).size > > will return the number of hits in the result set which will be at most > :num_docs which defaults to 10. You would need to set set num_docs to > 10000 if you wanted to get 10000 results back. > > What you want is something like this; > > result_set = index.search(query, :num_docs => 20) > puts result_set.size # => 20 > puts result_set.total_hits # => 293487 > > So total hits could be 10000000 but the number of results will still > only be the top 10 or whatever you set :num_docs to. If you really > want, you could set :num_docs to 1. You could also use search_each > like this; > > total_hits = index.search_each(query) do |doc_num, score| > @documents << index[doc_num] > endWow. It is really cool and simple. I aready *LOVE* Ferret. Hope that helps,> Dave > > > > But I am not sure that statement index.search(query).size will be > effective > > here. Because it returns an array of found documents. What if such > documents > > will be 100000?? I don''t want to select all this documents, just to know > how > > many found, and then select for example 10 of them > > > > index.search_each(query, :num_docs=>PAGE_SIZE, > > :first_doc=>PAGE_SIZE*(page_num-1)) do |doc_num, score| > > @documents << index[doc_num] > > end > > > > So quesition is: what is the most effective way to calculate (just > > calculate) number of found documents? > > > > -- > > anatol (http://pomozov.info) > > _______________________________________________ > > 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/20051126/9ab173d7/attachment.htm
It is just a small contribution to your great work. Looking forward to help you with Ferret further (Probably testing cferret on Windoze??) On 11/26/05, David Balmain <dbalmain.ml at gmail.com> wrote:> > Hi Anatol, > > Thanks for adding to the Howtos page. I really appreciate any help I can > get. > > Regards, > Dave >-- anatol (http://pomozov.info) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/ferret-talk/attachments/20051126/1ac75a3d/attachment.htm