Reputation: 1584
Having a bit of trouble with Thinking_Sphinx. To whit:
I have a Restaurant model and a Review Model with the following relationship:
Restaurant Has_many Reviews through relationships
Review belongs_to Restaurant through relationships
Each review has a rating that is off of a decimal system, with 0.5 increments.
I search for restaurants in Thinking Sphinx, and set the review rating as an attribute as follows (I do this so the results are ordered in descending order of rating value):
has reviews.rating, :as => :review_rating, :type => :float
And this is the error I get when I index Thinking Sphinx in the terminal:
indexing index 'restaurant_core'...
ERROR: source 'restaurant_core_0': expected attr type ('uint' or 'timestamp' or 'bigint') in sql_attr_multi, got 'float review_rating from field'.
ERROR: index 'restaurant_core': failed to configure some of the sources, will not index.
Interesting story: when I change the :type to :integer, as follows:
has reviews.rating, :as => :review_rating, :type => :integer
I don't get an error.
I am running Ruby on Rails 3.2.11, Thinking Sphinx 3.0.1, Ubuntu 12.10
Any help will be greatly appreciated.
Upvotes: 0
Views: 519
Reputation: 1773
Your problem is that one Restaurant
has many Review
s, but you're indexing reviews.rating
as a single value. You should change your indexing to either calculate some aggregate (e.g. mean, median, highest or lowest) of the reviews, or use a Multi-Valued Attribute (MVA). However, MVAs can only be integers, timestamps or booleans.
For example, to have the mean of the ratings as the attribute value, something like this should work:
has "AVG(reviews.rating)", :as => :review_rating, :type => :float
Of course, the exact code depends on your table names etc. Check the generated sphinx.conf
file if you're having trouble.
Upvotes: 0