hi all, i’m new to this group and currently using Rails 3.0.3 and meta_where 0.9.10.
i’m considering how to make a full-text searching feature to my project,
and my models, for example, should be defined like below:
class Group < ActiveRecord::Base
class Comment < ActiveRecord::Base
class User < ActiveRecord::Base
and db/seeds.rb is:
u1 = User.create :name => “user1”
u1.groups << Group.create(:title => “Group1”)
u1.comments << Comment.create(:message => “hi user2”)
u2 = User.create :name => “user2”
u2.groups << Group.create(:title => “Group2”)
u2.comments << Comment.create(:message => “hi user1”)
then SearchController#search will receive a [space] separated query,
and it should finds a collection of users that matched query joining groups and comments.
it may use User.search scope.
but i’ve confused, how do i write search algorism using ActiveRecord::Relation on habtm?
forced to hard code complex (or bothersome) SQL queries in the Rails code?
User.search(“user1”) == [u1, u2] is just a my expectation.
and i want to know how to construct `OR’ method-chain of ActiveRecord::Relation.
(User.where(“name = ?”, “user%”) | User.where(“name = ?”, “%1”)).class == Array, isn’t it?
my questions are above-mentioned, and please forgive me about faults of grammar.