Querying the SearchResults instance

Hi how do you search against the results returned by find_by_contents
using ferret?
i.e. how do you “search within these results”?
This is an acts_as_ferret question again…
thanks in advance…
cheers
caspar

Okay i found the reply below on the web and i think it maches pretty
much what i want to do. However i’m having problems principly being that
rails doesn;t seem to be able to see ferret. I installed acts_as_ferret
and i can use find_by_contents but when i tried to run the code below i
get the error below that: (two lines are commented out because i was
getting some errors along the lines of cant assing constant to
dynamic…) Anyway what do i have to do to be able to use ferret and
acts_as_ferret in my application. Thank you in advance very much for any
replies, I think ferret is the answer to my problems but thus far it has
proved a bit of challenge!

require ‘RMagick’
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)

filter = QueryFilter.new(bq)

@vobjects = Item.find_by_contents(search_text,:filter => filter,
:sort => [“section”, “sale_category”])

@vobjects = Item.find_by_contents(search_text,:filter => FILTER,

:sort => [“section”, “sale_category”])
redirect_to :results
end

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

caspar wrote:

Hi how do you search against the results returned by find_by_contents
using ferret?
i.e. how do you “search within these results”?
This is an acts_as_ferret question again…
thanks in advance…
cheers
caspar

On Sat, Jul 08, 2006 at 01:10:18AM +0200, caspar wrote:

Hi how do you search against the results returned by find_by_contents
using ferret?
i.e. how do you “search within these results”?
This is an acts_as_ferret question again…

As acts_as_ferret defaults to using AND as operator between query terms,
the easiest solution is to simply append the new query to the original
one.

If you configured aaf to use OR as default operator, you’ll have to AND
the original and the new query together, i.e.
“(#{old_query}) AND (#{new_query})”

Jens


webit! Gesellschaft für neue Medien mbH www.webit.de
Dipl.-Wirtschaftsingenieur Jens Krämer [email protected]
Schnorrstraße 76 Tel +49 351 46766 0
D-01069 Dresden Fax +49 351 46766 66

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