Aryk Grosz
2007-May-16 00:17 UTC
[Ferret-talk] return ONLY total_hits without querying from real database
Hey guys, I know I can run search(q).total_hits, but if I try to put :limit=>0 it gives me an error. I don''t want it actually query any of the results, I just want it to tell me how many total_hits I would have if I wanted to search it. How can I do this? -- Posted via http://www.ruby-forum.com/.
Jens Kraemer
2007-May-16 11:34 UTC
[Ferret-talk] return ONLY total_hits without querying from real database
On Wed, May 16, 2007 at 02:17:44AM +0200, Aryk Grosz wrote:> Hey guys, > > I know I can run search(q).total_hits, but if I try to put :limit=>0 it > gives me an error. I don''t want it actually query any of the results, I > just want it to tell me how many total_hits I would have if I wanted to > search it. > > How can I do this?Model.total_hits(query) Jens -- Jens Kr?mer webit! Gesellschaft f?r neue Medien mbH Schnorrstra?e 76 | 01069 Dresden Telefon +49 351 46766-0 | Telefax +49 351 46766-66 kraemer at webit.de | www.webit.de Amtsgericht Dresden | HRB 15422 GF Sven Haubold, Hagen Malessa
Aryk Grosz
2007-May-16 19:29 UTC
[Ferret-talk] return ONLY total_hits without querying from real databa
Hi Jens, I don''t have that method, could it have something to do with the fact that Im using Ferret::MixinActs::ARFerret Do I need to upgrade or can I just add that function? Aryk Jens Kraemer wrote:> On Wed, May 16, 2007 at 02:17:44AM +0200, Aryk Grosz wrote: >> Hey guys, >> >> I know I can run search(q).total_hits, but if I try to put :limit=>0 it >> gives me an error. I don''t want it actually query any of the results, I >> just want it to tell me how many total_hits I would have if I wanted to >> search it. >> >> How can I do this? > > Model.total_hits(query) > > Jens > > -- > Jens Kr?mer > webit! Gesellschaft f?r neue Medien mbH > Schnorrstra?e 76 | 01069 Dresden > Telefon +49 351 46766-0 | Telefax +49 351 46766-66 > kraemer at webit.de | www.webit.de > > Amtsgericht Dresden | HRB 15422 > GF Sven Haubold, Hagen Malessa-- Posted via http://www.ruby-forum.com/.
Jens Kraemer
2007-May-18 17:50 UTC
[Ferret-talk] return ONLY total_hits without querying from real databa
On Wed, May 16, 2007 at 09:29:56PM +0200, Aryk Grosz wrote:> Hi Jens, > > I don''t have that method, could it have something to do with the fact > that Im using > > Ferret::MixinActs::ARFerret > > Do I need to upgrade or can I just add that function?I''m not sure what you''re using there - I was thinking it''s acts_as_ferret because of the method name. Jens -- Jens Kr?mer webit! Gesellschaft f?r neue Medien mbH Schnorrstra?e 76 | 01069 Dresden Telefon +49 351 46766-0 | Telefax +49 351 46766-66 kraemer at webit.de | www.webit.de Amtsgericht Dresden | HRB 15422 GF Sven Haubold, Hagen Malessa
Aryk Grosz
2007-May-18 18:33 UTC
[Ferret-talk] return ONLY total_hits without querying from real databa
Here is what acts_as_ferret.rb says, maybe this is a really old version or something. # The Rails ActiveRecord Ferret Mixin. # # This mixin adds full text search capabilities to any Rails model. # # The current version emerged from on the original acts_as_ferret plugin done by # Kasper Weibel and a modified version done by Thomas Lockney, which both can be # found on the Ferret Wiki: http://ferret.davebalmain.com/trac/wiki/FerretOnRails. # # basic usage: # include the following in your model class (specifiying the fields you want to get indexed): # acts_as_ferret :fields => [ ''title'', ''description'' ] # # now you can use ModelClass.find_by_contents(query) to find instances of your model # whose indexed fields match a given query. All query terms are required by default, but # explicit OR queries are possible. This differs from the ferret default, but imho is the more # often needed/expected behaviour (more query terms result in less results). # # Released under the MIT license. # # Authors: # Kasper Weibel Nielsen-Refs (original author) # Jens Kraemer <jk at jkraemer.net> (active maintainer) -- Posted via http://www.ruby-forum.com/.
Jens Kraemer
2007-May-21 09:52 UTC
[Ferret-talk] return ONLY total_hits without querying from real databa
On Fri, May 18, 2007 at 08:33:22PM +0200, Aryk Grosz wrote:> Here is what acts_as_ferret.rb says, maybe this is a really old version > or something.yes, seems so. You should upgrade to the current stable version. Jens -- Jens Kr?mer webit! Gesellschaft f?r neue Medien mbH Schnorrstra?e 76 | 01069 Dresden Telefon +49 351 46766-0 | Telefax +49 351 46766-66 kraemer at webit.de | www.webit.de Amtsgericht Dresden | HRB 15422 GF Sven Haubold, Hagen Malessa
Aryk Grosz
2007-May-22 02:18 UTC
[Ferret-talk] return ONLY total_hits without querying from real databa
Hey Jens, I upgraded to the latest version. Everything works great, it even queries the results more efficiently. Great job! I don''t see any method for total_hits for multi_search. The model.total_hits works fine when you are just searching on one model. Any idea how to do only total_hits with multi_search? Also, I added a little fix to multi_search to allow users to include associations even if it works on one model but not the other. Here is what the code looks like. It currently works great on one-level include and somewhat hacky on two-level associations. Maybe you can find some use for it? http://pastie.caboo.se/63435 Aryk -- Posted via http://www.ruby-forum.com/.
Jens Kraemer
2007-May-22 09:28 UTC
[Ferret-talk] return ONLY total_hits without querying from real databa
On Tue, May 22, 2007 at 04:18:05AM +0200, Aryk Grosz wrote:> Hey Jens, > > I upgraded to the latest version. Everything works great, it even > queries the results more efficiently. Great job!thanks :)> I don''t see any method for total_hits for multi_search. The > model.total_hits works fine when you are just searching on one model. > > Any idea how to do only total_hits with multi_search?That was indeed missing. I just committed a fix for this to trunk. now you can give total_hits additional model classes with the :models option: A.total_hits(query, :models => [B, C])> Also, I added a little fix to multi_search to allow users to include > associations even if it works on one model but not the other. Here is > what the code looks like. It currently works great on one-level include > and somewhat hacky on two-level associations. Maybe you can find some > use for it? > > http://pastie.caboo.se/63435thanks, I integrated this :) Jens -- Jens Kr?mer webit! Gesellschaft f?r neue Medien mbH Schnorrstra?e 76 | 01069 Dresden Telefon +49 351 46766-0 | Telefax +49 351 46766-66 kraemer at webit.de | www.webit.de Amtsgericht Dresden | HRB 15422 GF Sven Haubold, Hagen Malessa