Sha256: f2c97d4a9dd62c0e8a0ec95b533daaae7da322aec0f920d829a142a7d4ae2513

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

require 'search_context'
class Foo <ActiveRecord::Base
  include SearchContext::Methods
  attr_accessible  :name
  
  # override the search_config if you are using some other search configuration
  def self.search_config
    "foos_search_config"
  end

  def self.alias_search_config
    "foos_alias_search_config"
  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(Foo.similar_terms(name).uniq) end.flatten.join(' | ')
       where("ts_rewrite(to_tsquery(?,?),'select original_tsquery,substitution_tsquery from foo_aliases WHERE to_tsquery('?','?') @>original_tsquery') @@ foos_vector",
           Foo.search_config,similar_terms,
           Foo.search_config, similar_terms)
      }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
search_steroids-0.0.1 spec/dummy/spec/tmp/app/models/foo.rb