Reputation: 5210
Is there an ability to order search results by association column in thinking sphinx?
I have index defined as follows:
ThinkingSphinx::Index.define :demand, :with => :active_record, :delta => true do
indexes client(:name), as: :client, sortable: true
has(created_at, updated_at, client_id)
end
The search is performed in controller:
Demand.search(params[:query], order: "#{params[:sort]} #{params[:direction].try(:upcase)}")
The value of params[order]
is "client.name"
, params[:direction]
is either "asc"
or "desc"
Here is the query that is generated by sphinx:
SELECT * FROM `demand_core`, `demand_delta` WHERE MATCH('Test_client @sphinx_internal_class_name (Demand)') AND sphinx_deleted = 0 ORDER BY client.name DESC LIMIT 0, 20
When I perform search I get the following error:
ThinkingSphinx::SyntaxError - sphinxql: syntax error, unexpected CONST_FLOAT, expecting $end near '.name DESC LIMIT 0, 20; SHOW META':
I've been searching for a while for the solution but couldn't find one. So the question is how can i apply ordering in sphinx after i perform the search?
Upvotes: 0
Views: 409
Reputation: 16226
You need to use the field/attribute names when sorting - so in your situation, it should be client
, not client.name
. Hopefully it's not too tricky to change what params[:sort] value is passed through to the controller.
Upvotes: 1