Hi Chris
If I'm understanding this correctly - you want Posts that match on either group
id *or* user id - but filters use *and* logic, and there's no way to change
that.
That said, it doesn't quite explain the results you're getting. I wonder if
that's related to you having a field and an attribute with the same name/alias
(group_id) - this may confuse Sphinx's indexer.
As a workaround to the initial problem, though... perhaps the following could
help?
has [user_id, submissions.group.users.id], :as => :user_ids
(I'm guessing your associations, but hopefully it's clear - pull all relevant
user ids for each post into a single multi-value attribute).
Cheers
--
Pat
On 02/11/2010, at 8:27 AM, chris wrote:
> I am doing a search for user posts that either they have made or that
> were made for a group they belong to.
>
> ## Method
> def self.find_all_activity_for_user(user_id, filter, page=1)
> group_ids = User.find(user_id).groups.map(&:id)
> groups = Group.all(:conditions => {:id => group_ids})
>
> puts "PostIds for User
> #{Post.find_all_by_user_id(user_id).map(&:id).join(',')}"
> puts "PostIds for Groups #{groups.map { |g|
> g.submissions.map(&:post_id)}.first}"
>
>
> Post.search(filter,
> :with => {:group_id => group_ids, :user_id =>
> user_id},
> :match_mode => :any,
> :page => page,
> :per_page => self.per_page)
> end
>
> ## puts output
> PostIds for User 1023110940,1023110938,1023110939
> PostIds for Groups 1023110939
>
> ## generated sql
> SELECT * FROM `posts` WHERE (`posts`.`id` IN (1023110939,1023110940))
> AND (posts.draft = 0) ORDER BY posts.created_at DESC
>
> ## AR class
> class Post < Act...
>
> define_index do
> indexes title, tags, body
> indexes [user.first_name, user.last_name], :as => :user_name
> indexes links.base_uri, :as => "link_url"
> indexes links.title, :as => "link_title"
> indexes links.description, :as => "link_description"
> indexes links.keywords, :as => "link_keywords"
> indexes links.source, :as => "link_source"
> indexes assets.upload_file_name, :as => "upload_file_name"
> indexes submissions.group_id, :as => "group_id"
>
> has user_id, created_at
> has submissions.group_id, :as => "group_id"
>
> where "draft = 0"
> set_property :delta => true
> end
>
> end
>
> Based on the ids it can be seen that right now all the posts are by
> the one user, while only one was to the group.
> PostIds for User 1023110940,1023110938,1023110939
> PostIds for Groups 1023110939
>
> So xx38, xx39, xx40 should be in the query, yet the final sql only
> searches for 2 of the items
> IN (1023110939,1023110940)
>
> Can what I am trying to do be done?
>
> --
> 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.
>
--
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.