I’m currently using Xapian for a client project and I needed to get the list of search terms for a given model. The idea was to present the user with a tool tip type window listing the possible valid search terms. Since the search bar was actually a parital and used for many different models, I wanted to dynamically discover the relevant search terms.
Here’s the simple way to get an array of the human readable search terms for the Project model:
Project.xapian_options[:terms].collect { |term| term[2] }
Since I was also using resource_controller, I was able to DRY this up nicely.
def search_terms
clazz = model_name.camelize.constantize
terms = clazz.xapian_options[:terms].collect { |term| term[2] }
terms.sort
end