Sha256: 1b64c46a8947edc82d90ad3761a2bdb831393af5602f8be37c875b80886e37d9

Contents?: true

Size: 877 Bytes

Versions: 3

Compression:

Stored size: 877 Bytes

Contents

module PgSearch
  module Features
    class DMetaphone
      def initialize(query, options, columns, model, normalizer)
        dmetaphone_normalizer = Normalizer.new(normalizer)
        options = (options || {}).merge(:dictionary => 'simple')
        @tsearch = TSearch.new(query, options, columns, model, dmetaphone_normalizer)
      end

      def conditions
        @tsearch.conditions
      end

      def rank
        @tsearch.rank
      end

      # Decorates a normalizer with dmetaphone processing.
      class Normalizer
        def initialize(normalizer_to_wrap)
          @decorated_normalizer = normalizer_to_wrap
        end

        def add_normalization(original_sql)
          otherwise_normalized_sql = @decorated_normalizer.add_normalization(original_sql)
          "pg_search_dmetaphone(#{otherwise_normalized_sql})"
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pg_search-0.5.4 lib/pg_search/features/dmetaphone.rb
pg_search-0.5.3 lib/pg_search/features/dmetaphone.rb
pg_search-0.5.2 lib/pg_search/features/dmetaphone.rb