Sha256: 4a0d7c0a6374816ba6dace2a3fce3d1fca6c1afd71b35f9200b86678b5cdd9c3

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

require 'logger'

module PgSearch
  class Document < ActiveRecord::Base
    include PgSearch

    self.table_name = 'pg_search_documents'
    belongs_to :searchable, :polymorphic => true

    before_validation :update_content,
      :unless => Proc.new { |doc| doc.searchable.nil? }

    # The logger might not have loaded yet.
    # https://github.com/Casecommons/pg_search/issues/26
    def self.logger
      super || Logger.new(STDERR)
    end

    pg_search_scope :search, lambda { |*args|
      options = if PgSearch.multisearch_options.respond_to?(:call)
                  PgSearch.multisearch_options.call(*args)
                else
                  {:query => args.first}.merge(PgSearch.multisearch_options)
                end

      {:against => :content}.merge(options)
    }

    private

    def update_content
      methods = Array(searchable.pg_search_multisearchable_options[:against])
      searchable_text = methods.map { |symbol| searchable.send(symbol) }.join(" ")
      self.content = searchable_text
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pg_search-1.0.5 lib/pg_search/document.rb