Hi!

That's a nice bug you've found there - getting the real result count is
a bit tricky when the result set is limited by both ferret's :limit
option and active record conditions. It's one of those things I always
wanted to fix but finally forgot about ;-)

I committed a possible fix right now that comes at the cost of an
additional ferret query and a "select count(*) where ...". Would be nice
if you could try out the current trunk of aaf to see if this fixes the
problem.

If the additional queries and counting are too slow for you (but first,
give it a try ;-), you could eliminate the need for active record
conditions by indexing the forum_id and creationDate columns as
untokenized values and let ferret handle them.

Jens



On Wed, May 02, 2007 at 12:12:08PM +0200, Chengcai He wrote:
> In my model Topic:
> 
> acts_as_ferret({ :fields => {:username => {:store => :yes, :boost =>
> 30}, :subject => {:store => :yes, :boost => 20}, :body => {:store =>
> :yes, :boost => 10}}, :remote => true }, { :analyzer =>
> Ferret::Analysis::RegExpAnalyzer.new(/./, false) })
> 
> def self.full_text_search(q, options = {}, find_options = {})
>    return nil if q.nil? or q==""
>    default_options = {:limit => 10, :page => 1}
>    options = default_options.merge options
> 
>    # get the offset based on what page we're on
>    options[:offset] = options[:limit] * (options.delete(:page).to_i-1)
> 
>    # now do the query with our options
>    results = Topic.find_by_contents(q, options, find_options)
>    return [results.total_hits, results]
> end
> 
> in my SearchController:
> 
> if params[:doSearch] == "true"
> if params[:query] == ""
> flash[:notice] = 'Please enter some words to search on.'
> else
> @conditions = " 1 = 1";
> if params[:dateRange] != ""
> @conditions += " and creationDate >= " + params[:dateRange]
> end
> if params[:forumID] != ""
> @conditions += " and forum_id = " + params[:forumID]
> end
> 
> @total, @topics = Topic.full_text_search(params[:query], {:page =>
> (params[:page]||1)}, {:conditions => @conditions})
> @pages = pages_for(@total)
> end
> 
> it always return only 10 search results. no more search result. i don't
> know why!
> 
> and this article doesn't work!
> http://www.ruby-forum.com/topic/93822
> 
> thanks!
> 
> -- 
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Ferret-talk mailing list
> [email protected]
> http://rubyforge.org/mailman/listinfo/ferret-talk
> 

-- 
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
[EMAIL PROTECTED] | www.webit.de
 
Amtsgericht Dresden | HRB 15422
GF Sven Haubold, Hagen Malessa
_______________________________________________
Ferret-talk mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ferret-talk

Reply via email to