Iterating through *all* search results (rather than being limited by :per_page)

38 views
Skip to first unread message

Murilo Soares Pereira

unread,
Jan 5, 2010, 9:09:50 PM1/5/10
to Thinking Sphinx
I did a little search and can't find a solution for this. The best I
found was 'paginated_each', but it seems to work at class level
(WillPaginate), so it doesn't work with ThinkingSphinx::Search'es.

Other plausible solution is overriding the default :per_page value,
but this doesn't look very clean to me. Does anybody know a better
way of iterating through all search results?

I hope I made my question clear.

--
Murilo Soares Pereira
http://www.comp.ufscar.br/~murilo

Pat Allan

unread,
Jan 5, 2010, 9:24:29 PM1/5/10
to thinkin...@googlegroups.com
Hi Murilo

There isn't any way to do this with Thinking Sphinx... your best bet is to override :per_page.

I guess as an alternative is to add a helper method that does each page - perhaps the following code does the job (I've not tested it):

def all_results_each(query, options = {}, &block)
search = ThinkingSphinx.search query, options
loop do
search.each do |match|
yield match
end
search = ThinkingSphinx.search query, options.merge(:page => search.next_page)
break unless search.next_page
end
end

Hope this helps.

--
Pat

> --
> You received this message because you are subscribed to the Google Groups "Thinking Sphinx" group.
> To post to this group, send email to thinkin...@googlegroups.com.
> To unsubscribe from this group, send email to thinking-sphi...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/thinking-sphinx?hl=en.
>
>

Murilo Soares Pereira

unread,
Jan 5, 2010, 9:31:31 PM1/5/10
to Thinking Sphinx
Your reply delay always surprises me, Pat.

Thank you very much for this piece of code, i'll plug it in right
away.

Kind regards.

--
Murilo Soares Pereira
http://www.comp.ufscar.br/~murilo

Reply all
Reply to author
Forward
0 new messages