On 7/10/06, BlueJay <[EMAIL PROTECTED]> wrote:
> I am looking to have a number of categories populated from my results of
> a search. For example, searching on "sport" would display all results
> for sport. I want to also have a number of categories to refine the
> documents down. So by clicking on the "Fishing" category or the
> "Shooting" category, I would only see the results on sport around that
> category.
>
> Now for the fun. I want to determine the total number of results in each
> category for a give search. So in the above, for a search on sport I
> want to display the results but in the Fishing item I want to say how
> many results there are in total before the user clicks on the item. For
> example in the pull down I want to display "Fishing (10001), Shooting
> (2003)".
Hi Clare,
The fastest way to do this would be to run the query multiple times.
So for your "sport" example you'd do something like this;
fishing_count = index.search_each("sport AND fishing", :num_docs => 1) {}
shooting_count = index.search_each("sport AND shooting", :num_docs => 1) {}
# etc.
Then go ahead and paginate your query as you usually would.
> I was going to do this in Ruby by doing a simple count for each category
> item on the returned result set, but I believe that this would mean
> returning all the results of a given query to Ruby in order to do this
> count and I am concerned that this would cause performance issues for
> large result sets.
Quite possibly. But running the query multiple times should be fine in
terms of performance. You could use filters instead of the code I
demonstrated above to further improve performance.
> If I put pagination into the mix and only display the first 50 results
> on the screen, would this add an additional complexity or would this
> just be called through Ruby?
>
> Thanks for your assistance with this...
I'm not exactly sure what you mean here when you say "would this be
called through ruby". I hope I've already answered your question. Let
me know if I didn't.
Cheers,
Dave
_______________________________________________
Ferret-talk mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ferret-talk