【问题标题】:sphinxql: syntax error, unexpected IDENTsphinxql:语法错误,意外 IDENT
【发布时间】:2013-07-31 06:54:44
【问题描述】:

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

【问题讨论】:

  • 是的,我认为这可能是问题所在,但不知道解决方案。

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


【解决方案1】:

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

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

我强烈推荐这些选项中的第一个(我认为它更简洁、准确),但这取决于你。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-08-03
  • 1970-01-01
  • 2011-10-28
  • 2014-12-18
  • 2011-05-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多