A
A
asdasda112017-12-07 07:36:03
Sphinx
asdasda11, 2017-12-07 07:36:03

How to enable related table sorting when using thinking_sphinx?

For example, there are two tables: books (id, title, date) and authors (id, name, country, date). When searching for a book, I display all information about the author. Those. As a result, we see the columns:

books.id, books.title, books.created_at, authors.name, authors.country, authors.created_at

In a normal situation, I can sort whatever I want by passing in orders like authors.country desc . However, when working with thinking_sphinx, this somehow does not work out. Now book_index.rb looks like this:
ThinkingSphinx::Index.define :book, with: :real_time do
  indexes title, sortable: true
  indexes author.name, as: :author_name, sortable: true
  indexes author.country, as: :author_country, sortable: true

  has title, type: string
  has author.name, type: string
  has author.country, type: string
  has created_at, type: :timestamp
  has author.created_at, type: :timestamp
end

When searching, respectively, I write:
Book.search params[:search], sql: {include: :author}, order: 'author_name asc'

In response I get:
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 am I doing wrong? Those. I would like to be able to sort data not only by the main table (books), but also by related attributes.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
asdasda11, 2017-12-07
@asdasda11

Silence .... Is it possible that everyone who uses Sphinx in their applications does not sort data by neighboring tables? ..

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question