Acts_as_ferret.. what does it actually do?

Okay in this plea for help I’m going to repeat some of what i posted
before but with a larger amount of background info in the hope that i
can get a decent grip on ferret before it wriggles away…

Firstly, what does installing the acts_as_ferret plugin actually do? I
install it and add it to my model and then the index is automatically
generated and a few methods are added to it and as far as i can see all
the index CRUD is being handled too. The Ferret gem is installed and
the index is generated and searchable so i assumed that i would be able
top use Ferret methods (other than the ones in acts as ferret)in my
application. when i try the code at the bottom of this post i get the
following errors (also in full at the bottom of post)

NameError: uninitialized constant BooleanQuery

So this means the rails/ruby/ is not seeing ferret right? so how do i
get rials to be able to see ferret? I have tried many variations on
include/require/ferret_config.rb but am obviously not getting it. Do i
need to do something extra if i want to simplicity of acts_as_ferret and
the power of Ferret?
If anyone out there knows what th eproblem is then please get in touch,
also does anyone use acts_as_ferret successfully in an application doing
more than just using find_by_contents? Thnaks in advance for any
replies/help
cheers
caspar

#####extract from model

require ‘ferret’

class VoObject < ActiveRecord::Base
acts_as_ferret :fields=>
[‘short_description’,‘section’,‘sale_category’,‘sale_type’,‘outcode’]

def VoObject.refine_search(search_input)
bq = BooleanQuery.new
bq.add_query(TermQuery.new(Term.new(“section”, search_input),
BooleanClause::Occur::Should))
filter = QueryFilter.new(bq)
@vobjects = Item.find_by_contents(search_text,:filter => filter,
:sort => [“section”, “sale_category”])
redirect_to :results
end

############ I get this ##############

ruby script/console
Loading development environment.

VoObject.refine_search(‘housing’)
NameError: uninitialized constant BooleanQuery
from
/usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:123:in
const_missing' from /usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:131:inconst_missing’
from
/usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:133:in
const_missing' from script/../config/../config/../app/models/vo_object.rb:22:inrefine_search’
from (irb):1

On 7/10/06, Caspar [email protected] wrote:

application. when i try the code at the bottom of this post i get the
following errors (also in full at the bottom of post)

NameError: uninitialized constant BooleanQuery

Basically you just need to include the Search module in your code. ie.

include Ferret::Search

This could be dangerous so it is often better to include the full
class path as I demonstrate bellow.

caspar
def VoObject.refine_search(search_input)
bq = BooleanQuery.new
bq.add_query(TermQuery.new(Term.new(“section”, search_input),
BooleanClause::Occur::Should))
filter = QueryFilter.new(bq)
@vobjects = Item.find_by_contents(search_text,:filter => filter,
:sort => [“section”, “sale_category”])
redirect_to :results
end

def VoObject.refine_search(search_input)
bq = Ferret::Search::BooleanQuery.new
bq.add_query(Ferret::Search::TermQuery.new(Ferret::Index::Term.new(“section”,
search_input),
Ferret::Search::BooleanClause::Occur::Should))
filter = Ferret::Search::QueryFilter.new(bq)
@vobjects = Item.find_by_contents(search_text,:filter => filter,
:sort => [“section”, “sale_category”])
redirect_to :results
end

Please let me know if you are still having problems.

Cheers,
Dave

Hi okay thank you very much for replying, I’m very impressed with ferret
and more impressed by you answering support questions, excellent work!

anyway update

wrong number of arguments (2 for 1)

RAILS_ROOT: script/…/config/…
Application Trace | Framework Trace | Full Trace
#{RAILS_ROOT}/app/models/vo_object.rb:26:in initialize' #{RAILS_ROOT}/app/models/vo_object.rb:26:inrefine_search’
#{RAILS_ROOT}/app/controllers/search_controller.rb:34:in `refine’

line 26:
bq.add_query(Ferret::Search::TermQuery.new(Ferret::Index::Term.new(“section”,search_input),
Ferret::Search::BooleanClause::Occur::SHOULD))

sorry I’m just rushing off for the commute home and have only just tried
this, have not had enough time to play around with it yet so if its a
stupid mistake by me i’m sorry for time wasting!

regards
caspar

David B. wrote:

On 7/10/06, Caspar [email protected] wrote:

application. when i try the code at the bottom of this post i get the
following errors (also in full at the bottom of post)

NameError: uninitialized constant BooleanQuery

Basically you just need to include the Search module in your code. ie.

include Ferret::Search

This could be dangerous so it is often better to include the full
class path as I demonstrate bellow.

caspar
def VoObject.refine_search(search_input)
bq = BooleanQuery.new
bq.add_query(TermQuery.new(Term.new(“section”, search_input),
BooleanClause::Occur::Should))
filter = QueryFilter.new(bq)
@vobjects = Item.find_by_contents(search_text,:filter => filter,
:sort => [“section”, “sale_category”])
redirect_to :results
end

def VoObject.refine_search(search_input)
bq = Ferret::Search::BooleanQuery.new
bq.add_query(Ferret::Search::TermQuery.new(Ferret::Index::Term.new(“section”,
search_input),
Ferret::Search::BooleanClause::Occur::Should))
filter = Ferret::Search::QueryFilter.new(bq)
@vobjects = Item.find_by_contents(search_text,:filter => filter,
:sort => [“section”, “sale_category”])
redirect_to :results
end

Please let me know if you are still having problems.

Cheers,
Dave

On 7/10/06, Caspar [email protected] wrote:

RAILS_ROOT: script/…/config/…
Application Trace | Framework Trace | Full Trace
#{RAILS_ROOT}/app/models/vo_object.rb:26:in initialize' #{RAILS_ROOT}/app/models/vo_object.rb:26:inrefine_search’
#{RAILS_ROOT}/app/controllers/search_controller.rb:34:in `refine’

line 26:
bq.add_query(Ferret::Search::TermQuery.new(Ferret::Index::Term.new(“section”,search_input),
Ferret::Search::BooleanClause::Occur::SHOULD))

Looks like you’ve got the brackets in the wrong place. I have to take
partial responsibility since didn’t pick it up the first time either.
Try this;

bq.add_query(Ferret::Search::TermQuery.new(Ferret::Index::Term.new(“section”,search_input)),
Ferret::Search::BooleanClause::Occur::SHOULD)

sorry I’m just rushing off for the commute home and have only just tried
this, have not had enough time to play around with it yet so if its a
stupid mistake by me i’m sorry for time wasting!

No worries. :smiley:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs