Sha256: dfd8c0dab2c6b87dacc67ec12edc252cdcbbd8e1f6ec5a5c196ad3a639a35554

Contents?: true

Size: 776 Bytes

Versions: 4

Compression:

Stored size: 776 Bytes

Contents

module Enjoy::Search::Searchable
  extend ActiveSupport::Concern

  module ClassMethods
    def enjoy_search_fts_index(*opts)
      if Enjoy::Search.mongoid?
        opts = opts.extract_options!
        index(
          {
            name: "text"
          }.merge(opts[:fields]),
          {
            default_language: opts[:default_language] || "russian",
            weights: {
              name: 100
            }.merge(opts[:weights]),
            name: opts[:name]
          }
        )
      end
    end
  end

  included do
    scope :fts, -> (query) {
      ret = where({"$text": { "$search": query.to_s }})
      ret.options[:fields] = {"score": { "$meta": "textScore" }}
      ret.options[:sort] = {"score": { "$meta": "textScore" }}
      ret
    }
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
enjoy_cms_search-0.4.1 app/models/concerns/enjoy/search/searchable.rb
enjoy_cms_search-0.4.0.1 app/models/concerns/enjoy/search/searchable.rb
enjoy_cms_search-0.4.0 app/models/concerns/enjoy/search/searchable.rb
enjoy_cms_search-0.4.0.beta3 app/models/concerns/enjoy/search/searchable.rb