Hi Mike
I think the first thing to be aware of is that you're trying to sort by a set
of values - each category can have multiple client categories - so handling
that from either a Sphinx or SQL perspective isn't a simple matter. What do you
expect to happen if a category has three different client category positions?
Which one should be considered the value to sort by?
--
Pat
On 18/06/2012, at 5:41 PM, mikej wrote:
> Client
> has_many :client_categories
> has_many :categories, :through => :client_categories
>
> ClientCategory
> belongs_to :category
> belongs_to :client
>
> Category
> has_many :client_categories
> has_many :clients, :through => :client_categories
>
> Each client can order their categories individually, so client_categories
> includes a position column. Each ClientCategory is further subdivided and may
> be in a group (group_id).
>
> I am wanting to search categories for a given client and return Categories -
> ordered first by client_categories.group, then client_categories.position
> then at the end of the search include categories not assigned to that client.
>
> I can do this by indexing client_categories and searching the ClientCategory
> model. This is very slow though.
>
> Can I do this through the Category Model?
>
> e.g.
>
> define_index do
> indexes name, :sortable => true
> has client_categories.client_id, :as => :category_client_id, :sortable =>
> true
> has client_categories.group_id, :as => :category_group_id, :sortable =>
> true
> end
>
> Ignoring trying to include clients not assigned to categories at the moment:
>
> @categories = Category.search nil,:with=>{:category_client_id=>1},:order =>
> :category_group_id
>
> This does not work.
>
> Also not sure how to include categories not assigned to the client.
>
> Any thoughts much appreciated, big thanks,
>
> Mike
>
> --
> You received this message because you are subscribed to the Google Groups
> "Thinking Sphinx" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/thinking-sphinx/-/S44OFcKXDIAJ.
> 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.