Closed dekanaxo closed 6 years ago
Generally everything you're doing looks right. Have you run ts:regenerate
(or just ts:rebuild
on v3.4+) since adding in the sortable option? Making a field sortable means it'll add a corresponding attribute under the hood, which means regeneration is required.
Also: I'd recommend giving your string attributes aliases so they don't conflict with the fields and other attributes. e.g. You've got title
twice, and created_at
(for both book and author) twice.
Okay, I'll try later. Thank you! I spent on the solution of the problem about 6 hours and gave up. Want to relax a bit...
This issue's been quiet for a month, so I'm going to close it. If you have further questions though, please do comment and we can re-open it :)
I have the same issues.. Do you find a solution ?
@frerotg if you'd like, you're welcome to open a new issue - feel free to go into detail about what you're trying to do, your index definitions, and the version of TS that you're using :)
For example there are two tables: books (id, title, date) and authors (id, name, country, date). When you search for the book, I show all the information about the author. Thus, we will see the columns:
books.id books.title books.created_at authors.name authors.country authors.created_at
Usually in a situation I can sort as you like, using for example
orders authors.country desc
. However, when working with thinking_sphinx I did not get to do so. Now code of book_index.rb looks like this:Now, to search, I write this:
Book.search params[:search], sql: {include: :author}, order: 'author_name asc'
And this answer:
index book_core: sort_by attribute 'author_name' not found - SELECT * FROM 'book_core' WHERE MATCH('blablabla') AND 'sphinx_deleted' = 0 ORDER BY 'author_name' asc LIMIT 0, 50; SHOW META
Question: what's wrong? I would like to be able to sort the data in the main table (books), but also the associated attributes (such as author.created_at).
Thanks!