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.
精彩评论