狮身人面像的范围没有任何回报

时间:2011-10-28 11:39:48

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

我正在尝试创建一个sphinx将索引的简单范围(Ruby on Rails)。正常范围返回它应该的范围,sphinx范围不返回任何结果。

define_index do
  # fields
  indexes :name
  indexes author
  indexes description
  indexes list_of_tags
  indexes approved

  # attributes
  has created_at, updated_at, downloads

  # delta indexing
  set_property :delta => true

  # weighting fields
  set_property :field_weights => {
    :name => 10,
    list_of_tags => 6,
    author => 5,
    description => 4,
  }

正常范围:

scope :approved, where(:approved => true)

狮身人面像范围:

sphinx_scope(:approval_scope) {
  {:conditions => {:approved => "true"}}
}

Approved是一个布尔字段,但是,由于我将其索引为一个字段,我相信它的值被视为一个字符串。无论如何,让sphinx范围的值为“true”或true也没有区别 - Theme.approval_score仍然返回0结果,与Theme.approval不同。我希望我错过了一些简单的事情......

1 个答案:

答案 0 :(得分:4)

使用已批准

define_index do
  # fields
  ...
  has approved
  ...
end

然后

sphinx_scope(:approval_scope) {
  {:with => {:approved => true}}
}