sphinxql:语法错误,意外IDENT

时间:2013-07-31 06:54:44

标签: ruby-on-rails-3 thinking-sphinx

使用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

错误在部分集合的行中被抛出:@posts_by_state,但是同一部分的另外两个实例工作得很好。国家排序就是把它抛弃了。

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 个答案:

答案 0 :(得分:3)

Sphinx中的字符串属性只能用于排序 - 不能过滤,不能用于分组 - 因此您可以选择解决此问题的方法如下:

  • 将其拉出到关联的模型(State或PostState,也许?),然后用外键整数过滤。
  • 将该值存储为字段,并使用:conditions而不是:with。
  • CRC32 values围绕它。

我强烈推荐第一个选项(我认为它更清晰,准确),但这取决于你。