Is there a way to have searches no use some indexed fields, when
processing a query?
context:
I have a model Foo that holds some information in two languages :
text1_nl, text2_nl, text3_nl
and
text1_en, text2_en, text3_en
Some other fields are common to both languages and indexed as well
first_name, last_name
Depending on the visitor language choice I need to exclude the first
three, or last three fields when query processing. Is this doable
relatively simply?
I guess I could use two indexes, but I’d like to keep using
acts_as_ferret if possible.
I would setup your models differently, using Single-Table Inheritance
(STI). (You can get more info on it by Googling “rails single table
inheritance”.) For your example, you’d have a table with columns like:
I would setup your models differently, using Single-Table Inheritance
STI would be impractical (I don’t want to add a useless “type”
column), but plain inheritance sounds like a very good idea.
class Text << ActiveRecord::Base
acts_as_ferret(… declare all fields here )
end>
You’d then subclass this with two other classes:
class EnglishText << Text
end
class DutchText << Text
end
I guess you meant :
class Text << ActiveRecord::Base
end
class EnglishText << Text
acts_as_ferret :fields => [name, text_en]
end
class DutchText << Text
acts_as_ferret :fields => [name, text_nl]
end
On Wed, May 16, 2007 at 08:55:46PM +0200, Alain R. wrote:
Some other fields are common to both languages and indexed as well
first_name, last_name
Depending on the visitor language choice I need to exclude the first
three, or last three fields when query processing. Is this doable
relatively simply?
I guess I could use two indexes, but I’d like to keep using
acts_as_ferret if possible.
I’m refactoring/upgrading an “old” (1-year) app, where I used to do
all the ferret index stuff myself (callbacks, queries, …), to the
mucho simpler interface offered by acts_as_ferret. AFAIK, aaf only
works with string queries, so if there is a string-based solution that
works, I’d rather use this one. If there is none, I’ll bite the bullet
and follow your advice. “A man’s got to do, what a man’s got to do”
Alain,
i’m no AAF expert, but afaik most methods of aaf are using
find_id_by_contents… which is accepting a query parameter…
that query parameter gets forwarded to ferrets own search_each.
search_each accepts strings or ferret query objects… so i would
assume that you can pass a OO-Query to AAF. And anything else
would have surprised me… as Jens code is quite sophisticated
Hey Alain,
finally jumped on board? hope to see you in berlin in a few
months
Can’t wait to register. My credit card is on the starting-blocks.
Is this the proper syntax for multi-words queries:
first_name|last_name:(jo* OR va*)
i would suggest to use the OO-Syntax for more complex queries … like
query = BooleanQuery.new
I’m refactoring/upgrading an “old” (1-year) app, where I used to do
all the ferret index stuff myself (callbacks, queries, …), to the
mucho simpler interface offered by acts_as_ferret. AFAIK, aaf only
works with string queries, so if there is a string-based solution that
works, I’d rather use this one. If there is none, I’ll bite the bullet
and follow your advice. “A man’s got to do, what a man’s got to do”
Alain
–
Alain R.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.