Hello!
I'm adding a search feature in a project and just started using Sphinx
and Thinking Sphinx about a week ago. I'm seeking some help from
Sphinx Gurus here, can any of you help me? I would be extremely
grateful, as I've been stuck on this for a couple of days already.
I basically have 3 models involved in this:
Project:
has_many :members, :through => :memberships, :source => :user
Membership, which links users to projects
User:
has_many :projects, :through => :memberships
Users should be able to search for projects. However, depending on
their access level, they can see more or less projects:
- Admin users can see all projects (public and private). So I got
something like this:
Project.search options[:q], :page => 1, :per_page => 10
Simple and easy, I can handle that.
- Normal users can only see projects they are member of. How can I do
this?
I guess (but i could be completely wrong) I need this in my Project
index:
has members(:id), :as => :member_ids
But how can I use it? Or what should I use?
Project.search options[:q], :page => 1, :per_page => 10,
:with => { } # member_ids.include?(@user.id)
- I kept the best for the end : Moderators can view all public
projects and all projects they are a member of.It's basically the same
as a normal user, with some "OR" condition cream on top of it:
Project.search options[:q], :page => 1, :per_page => 10,
:with => { :private => 0 } # OR member_ids.include?
(@user.id)
I'm already using the "OR" trick to search within my contacts but I
cant apply it here as it only works when the permission is within the
same model:
has "IF(view_permission = 0, 0, contact_owner)", :as => :owner, :type
=> :integer
Any idea how to deal with moderators and normal users searches?
Thanks a lot to everyone for at least reading this. Extra thanks for
those who can help!
PS: In the worst case scenario, is there a way of "unpaginating" the
results i get from TS, removing projects that don't match the
conditions, then re-paginating? I know that's a terrible solution and
I want to avoid it at all costs. However, we'll never have more than
100 projects in the database and I'd rather have a that than no search
at all.
--
You received this message because you are subscribed to the Google Groups
"Thinking Sphinx" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/thinking-sphinx?hl=en.