开发者

Get fields and attributes defined by thinking_sphinx

How can i get list of defined thinking_sphinx attributes and fields on a model? In particular i want to check whether input att开发者_JAVA技巧ribute is defined for sphinx

example definition:

has store.name, :as => :store_name

i want something like Model.sphinx_attributes.include? :store_name


The following should do the trick:

Model.sphinx_indexes.collect { |index|
  index.attributes.collect &:unique_name
}.flatten.include?(:store_name)

Fields are much the same:

Model.sphinx_indexes.collect { |index|
  index.fields.collect &:unique_name
}

Before running either, it's good practice to run this first, to ensure the indexes are loaded:

Model.define_indexes

If they are already loaded, that method will do nothing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜