sandmark
2011-Jan-14 09:59 UTC
[Rail3] How to construct full-text search for habtm associations
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
has_and_belongs_to_many :users
# :title (string)
end
class Comment < ActiveRecord::Base
has_and_belongs_to_many :users
# :message (string)
end
class User < ActiveRecord::Base
has_and_belongs_to_many :comments
has_and_belongs_to_many :groups
# :name (string)
end
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.
any ideas?
thx.
--
sandmark
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Apparently Analagous Threads
- self referential habtm using join tables
- Prevent duplicate HABTM associations
- self-referential many-to-many using a join model
- Message Stopped by Bothways : Block Greater than 40 recip
- Anomalous outputs from rbeta when using two different random number seeds
