【问题标题】:sql_range_query error with Sphinx狮身人面像的 sql_range_query 错误
【发布时间】:2011-06-30 18:55:53
【问题描述】:

在我的生产服务器上设置 Sphinx 时,尝试索引时出现了这个奇怪的错误

ERROR: index 'benefit_core': sql_range_query: You have an error in your SQL 
syntax; check the manual that corresponds to your MySQL server version for the 
right syntax to use near '' at line 1

这不会发生在我的本地机器上。是的,这是一个空字符串。

以前有人见过这类问题吗?

benefit.rb

define_index do 
  # Fields
  indexes category
  indexes title
  indexes tags
  indexes description
  indexes brief_description
  indexes brand
  indexes short_description
  indexes long_description
  indexes benefit_description
  indexes address.city
  indexes address.state
  indexes address.street_1
  where sanitize_sql(["active = true and expiration > ?", Time.now]) 
  set_property :field_weights => {
    :title => 15,
    :tags => 10,
    :brand => 10,
    :description => 3
  }
end

Thinking-Sphinx - 1.4.4

狮身人面像 - 0.9.9

谢谢!

【问题讨论】:

  • 请从您的模型中发布您的查询和您的 define_index 块。
  • @Dex 我添加了模型的define_index。索引期间发生错误,所以我什至没有机会测试查询。
  • 什么时候看到错误?你跑了rake ts:configrake ts:rebuild

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


【解决方案1】:

确保您运行的是最新版本的 Thinking Sphinx,3.0.4 左右。 sanitize_sql 似乎有一些问题

https://github.com/freelancing-god/thinking-sphinx/issues/213

也尝试将行重写为

where sanitize_sql(["active = ? and expiration > ?", true, Time.now]) 

还可以尝试注释掉所有行并逐渐将它们添加回来以确定错误发生的确切位置。

【讨论】:

    【解决方案2】:

    问题最终出在sanitize_sql 方法上。我将那行替换为:

    where "active = true AND expiration > \"#{Time.now.to_formatted_s(:db)}\""
    

    感谢您的帮助!

    【讨论】:

      猜你喜欢
      • 2014-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-27
      • 1970-01-01
      • 2013-11-29
      相关资源
      最近更新 更多