Can you alias fields in acts_as_ferret?

Is there any way to set a field name that is different than the method
name used to populate it?

My example:

In Rails, I’m using acts_as_ferret on a Article model that has_many
Authors. I want to be able to index authors’ names with each article.
Since @article.authors yields an array of Author objects (and not an
indexable string), I’ve created this method in my Article model:

def authors_aaf
@authors.collect {|a| a.name }.to_sentence
end

I call it “authors_aaf” because “authors” would cause a conflict. But I
want my field name to be “authors”, because that makes the most sense.
(Users shouldn’t have to type “authors_aaf:Joe” to search by author.)

Any idea how this can/should be done?

On Mon, Oct 08, 2007 at 04:30:12AM +0200, Chase DuBois wrote:

def authors_aaf
@authors.collect {|a| a.name }.to_sentence
end

I call it “authors_aaf” because “authors” would cause a conflict. But I
want my field name to be “authors”, because that makes the most sense.
(Users shouldn’t have to type “authors_aaf:Joe” to search by author.)

Any idea how this can/should be done?

You could pass the query through a de-aliasing helper method - something
that does query.gsub!(/authors:/, ‘authors_aaf:’) - before handing off
the
query string to ferret.

-Chris