Sha256: 1025c544dc5e22fcc6996122cbf617962768233a5923262a89d05f1ee66e5834

Contents?: true

Size: 757 Bytes

Versions: 16

Compression:

Stored size: 757 Bytes

Contents

require "active_support/core_ext/module/delegation"

module PgSearch
  module Features
    class Trigram
      def initialize(query, options, columns, model, normalizer)
        @query = query
        @options = options
        @columns = columns
        @model = model
        @normalizer = normalizer
      end

      def conditions
        ["(#{@normalizer.add_normalization(document)}) % #{@normalizer.add_normalization(":query")}", {:query => @query}]
      end

      def rank
        ["similarity((#{@normalizer.add_normalization(document)}), #{@normalizer.add_normalization(":query")})", {:query => @query}]
      end

      private

      def document
        @columns.map { |column| column.to_sql }.join(" || ' ' || ")
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
pg_search-0.2.2 lib/pg_search/features/trigram.rb
pg_search-0.5.1 lib/pg_search/features/trigram.rb
pg_search-0.5 lib/pg_search/features/trigram.rb
pg_search-0.4.2 lib/pg_search/features/trigram.rb
pg_search-0.4.1 lib/pg_search/features/trigram.rb
pg_search-0.2.1 lib/pg_search/features/trigram.rb
pg_search-0.4 lib/pg_search/features/trigram.rb
pg_search-0.3.4 lib/pg_search/features/trigram.rb
pg_search-0.3.3 lib/pg_search/features/trigram.rb
pg_search-0.3.2 lib/pg_search/features/trigram.rb
pg_search-0.3.1 lib/pg_search/features/trigram.rb
pg_search-0.3 lib/pg_search/features/trigram.rb
pg_search-0.2 lib/pg_search/features/trigram.rb
pg_search-0.1.1 lib/pg_search/features/trigram.rb
pg_search-0.1 lib/pg_search/features/trigram.rb
pg_search-0.0.2 lib/pg_search/features/trigram.rb