思维狮身人面像范围搜索中缺少引号

missing quotes in thinking sphinx scoped search

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

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

这是我拥有的:

indices/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 => {:status => '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 => {:status => "'ARCHIVED'"},它会添加单引号并且查询成功。 :)

这是编写范围的正确方法,还是有更好的方法?

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

首先:对引号的需求是一个错误——Sphinx 直到最近才允许过滤字符串属性,因此这在不久前还没有实现。我已经修补了 Riddle(gem,它是 Sphinx 功能的纯 Ruby 包装器,并由 Thinking Sphinx 使用),您可以在 Gemfile 中使用它进行最新的旋转:

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

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