Acts_as_ferret: can i specify a search on 1 field as suppose

to the ones i defined in my model? for example if in the model i specify
acts_as_ferret to index only column 1, 2, and 3 in my table…how can i
perform a search just for column 1 if need be.

for example, id like to give the user the ability to just search on
title name vs description, etc…

thanks!

On 10/16/06, poipu [email protected] wrote:

to the ones i defined in my model? for example if in the model i specify
acts_as_ferret to index only column 1, 2, and 3 in my table…how can i
perform a search just for column 1 if need be.

for example, id like to give the user the ability to just search on
title name vs description, etc…

thanks!

You prepend the search with the field-name and a colon. For example:

title:"War and Peace" author:(Leo Tolstoy)

Hope that helps,
Dave

hi dave, thanks for the reply.

so just to clarify for myself…if in my view i have a category textbox
and a query text box,all i need to do is

model.find_by_contents(params[:category]+":"+params[:query])

?

On 10/17/06, poipu [email protected] wrote:

hi dave, thanks for the reply.

so just to clarify for myself…if in my view i have a category textbox
and a query text box,all i need to do is

model.find_by_contents(params[:category]+":"+params[:query])

If params[:category] is the name of the field you want to search then
yes, almost. You should also put brackets around params[:query] so the
whole query is restricted to the field.

model.find_by_contents(params[:category]+":("+params[:query] + “)”)

Other wise the query ruby AND rails on the :title field would look like
this

title:ruby AND rails

instead of:

title:(ruby AND rails)

Hope that makes sense.
Dave

hello,
i would like to use find_by_contents, have it search the table for
things that match my query, only if a column field is a certain value.

for example i have an application for all the states in usa. If i am
using the NJ search box, i would only like to limit my searches for
where the state name is equal to new jersey.

can i do this?

from the above example it seems like i am looking for something like
this?

Model.find_by_contents(state:‘nj’+"+statesearchstring")

where state is the name of the column in my DB.

thanks,

hi dave, thank you so much for your post. greatly appriciated!

maybe something like

find_by_contents(searchstring +" "+ state:selectedstate)

Hi Jens Thank you!

On Fri, Dec 01, 2006 at 06:46:44AM +0100, koloa wrote:

maybe something like

find_by_contents(searchstring +" "+ state:selectedstate)

make that

find_by_contents("#{searchstring} +state:#{selectedstate}")

and it should work. if you store the state acronym in the state field,
it might be a good idea to give :index => :untokenized as an option for
this field in your call to acts_as_ferret:

acts_as_ferret :fields => {
:content => {},
:state => { :index => :untokenized },
… any other fields you want to have indexed
}

this works great for i.e. having a select box to let the user select a
state he wants to search in. Generally, not tokenizing a field is a good
thing whenever you expect exact matches on a field, or want to sort your
results using this field. You can have a look at the Ferret API docs
(class FieldInfo) for more options and their explanations.

cheers,
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