You'll need to actually search on Setting - as Sphinx has no concept of
key-value attributes. I'm guessing data is an integer or float, given you'd
like to use a range?
define_index do
indexes "'something'", :as => :one_field_is_required
has id, :as => :setting_id
has data, user_id
end
@settings = Setting.search :with => {:setting_id => (variable id), :data =>
a..b},
:group_by => 'user_id',
:group_function => :attr
Because you're grouping by user_id, you'll only get one result per user, so
then when you paginate through, you can display the user of the setting:
<% @settings.each do |setting| %>
<%= setting.user.name %>
<% end %>
Let me know how you go.
Cheers
--
Pat
On 13/05/2011, at 6:20 PM, mechu wrote:
> I need to make a query with thinking_sphinx, I'll try to explain it
> the best I can
> User has_many settings
> setting has attributes "id" and "data"
> I need to make a query which does the following:
> Find all users who have a setting with id=(variable id) and "data"
> between (a) and (b)
>
> how do I need to configure the index and write the query? I couldn't
> find it anywhere...
>
> --
> 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.