【问题标题】:missing quotes in thinking sphinx scoped search在思考狮身人面像范围搜索中缺少引号
【发布时间】:2017-01-04 04:54:22
【问题描述】:

我想要一个只会搜索当前记录的 sphinx_scope。每个数据库记录都有一个字段status,其值为CURRENTARCHIVED

我已经做到了,但我必须使用一个奇怪的结构才能到达那里;可能有更好的方法。

这是我所拥有的:

索引/letter_index.rb

ThinkingSphinx::Index.define :letter, :with => :real_time do
  # fields
  indexes title, :sortable => true
  indexes content

  # attributes
  has status, :type => :string
  has issue_date, :type => :timestamp
  has created_at, :type => :timestamp
  has updated_at, :type => :timestamp
end

models/letter.rb

class Letter < ActiveRecord::Base
  include ThinkingSphinx::Scopes
  after_save ThinkingSphinx::RealTime.callback_for(:letter)

  .. snip ..

  sphinx_scope(:archived) {
    {:with => {:status => "'ARCHIVED'"}}
  }

我遇到的问题是,如果我使用:with =&gt; {:status =&gt; 'ARCHIVED'},我的查询结果是

SELECT * FROM `letter_core` WHERE MATCH('search term') AND `status` = ARCHIVED AND `sphinx_deleted` = 0 LIMIT 0, 20
ThinkingSphinx::SyntaxError: sphinxql: syntax error, unexpected IDENT, expecting CONST_INT (or 4 other tokens) near 'ARCHIVED AND `sphinx_deleted` = 0 LIMIT 0, 20; SHOW META'

但是,如果我将其构造为:with =&gt; {:status =&gt; "'ARCHIVED'"},那么它会添加单引号并且查询成功。 :)

这是编写作用域的正确方法,还是有更好的方法?

额外问题:我在哪里可以找到范围内允许的文档,例如 :order:with:conditions 等。

【问题讨论】:

    标签: thinking-sphinx


    【解决方案1】:

    首先:对引号的需求是一个错误——Sphinx 直到最近才允许过滤字符串属性,因此为什么这不是很久以前的东西。我已经修补了 Riddle(它是 Sphinx 功能的纯 Ruby 包装器,由 Thinking Sphinx 使用),您可以在您的 Gemfile 中使用它提供最新版本:

    gem 'riddle', '~> 2.0',
      :git    => 'git://github.com/pat/riddle.git',
      :branch => 'develop',
      :ref    => '8aec79fdf4'
    

    至于什么可以进入 Sphinx 范围:任何可以进入正常搜索调用的内容。

    【讨论】:

    • 是的,可以修复它。我怎么知道什么时候可以从 gemfile 中删除?
    • 嗯,它在开发中修复了它。但是生产中断了……因为 sphinx 是 2.0.4。我没有意识到我有不同版本的狮身人面像。更新为 2.2.11-- couldn't bind to 127.0.0.1-- sudo service sphinxsearch stopbundle exec rake ts:regenerate。哇,3小时的撞头减为一句话!
    • 刚刚发布了 Riddle 的 v2.1.0,所以如果你从 Gemfile 中删除该列表,然后运行bundle update riddle,它应该确保你使用的是 2.1.0。很遗憾听到您在升级时遇到了一些痛苦,但也很高兴知道您已经弄清楚了!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多