问题
Getting this error with sphinx 2
sphinxql: syntax error, unexpected IDENT, expecting CONST_INT or CONST_FLOAT or '-' near 'WI AND published = 1 AND sphinx_deleted = 0 LIMIT 0, 10; SHOW META'
index.html.erb
error is being thrown in the template at the line of a partial collection: @posts_by_state, but two other instances of the same partial are working great. The State sort is what is throwing it off.
posts_controller.rb
@posts_by_state = Post.search(params[:search], with: { state: current_user.state, published: true }, :page => params[:page], :per_page => 10)
post_index.rb
ThinkingSphinx::Index.define :post, :with => :active_record do
indexes :title, as: :post_title
indexes :desc, as: :description
indexes tags(:name), as: :tag_name
#indexes happening_on, sortable: true
#has author_id, published_at
has published_at
has last_touched
has state
has published
set_property:field_weights => {
:post_title => 5,
:description => 1,
:tag_name => 10
}
end
回答1:
String attributes in Sphinx can only be used for sorting - not filtering, not grouping - and so your options to work around this are as follows:
- Pull it out into an associated model (State or PostState, perhaps?), and then filter by the foreign key integer instead.
- Store that value as a field instead, and use :conditions instead of :with.
- Hack around it with CRC32 values.
I highly recommend the first of these options (I'd argue it's cleaner, accurate), but it's up to you.
来源:https://stackoverflow.com/questions/17963593/sphinxql-syntax-error-unexpected-ident