Sha256: 3747fdd9e720ad5263870bfd650bd34a79516daf0f56d9c7a49e72d106ca00f7

Contents?: true

Size: 1.34 KB

Versions: 1

Compression:

Stored size: 1.34 KB

Contents

require 'search_context'
class <%= class_name %> <ActiveRecord::Base
  include SearchContext::Methods
  attr_accessible <%if options.dynamic? -%>
    :count,<%end%> :name
  
  # override the search_config if you are using some other search configuration
  def self.search_config
    "<%= search_config_name %>"
  end

  def self.alias_search_config
    "<%= alias_search_config_name %>"
  end
  # central place for queries using this search context, if it makes sense to share the search queries amoung multiple duck-typed models.
  # for example, BottleSource, Bottle, Wine all use similar vocabulary and search configuration. and queries
  module Query extend ActiveSupport::Concern
    included do
      # this example demostrates synonyms and stop words implemented via the aliases table, which you have to figure out
      # how to populate on your own
      scope :fuzzy_match, lambda {|term1|
       similar_terms= term1.split(/ +/).inject([]) do |acc, name| [name].concat(<%= class_name %>.similar_terms(name).uniq) end.flatten.join(' | ')
       where("ts_rewrite(to_tsquery(?,?),'select original_tsquery,substitution_tsquery from <%=aliases_name%> WHERE to_tsquery('?','?') @>original_tsquery') @@ <%=column_name%>",
           <%= class_name %>.search_config,similar_terms,
           <%= class_name %>.search_config, similar_terms)
      }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
search_steroids-0.0.1 lib/generators/search_context/templates/model.rb