Sha256: a719f8c83cdd6fb3e826ce7b1c3ba4e4b8a2d7f165a2233d31d7cc84c1122090

Contents?: true

Size: 697 Bytes

Versions: 18

Compression:

Stored size: 697 Bytes

Contents

module FortyFacets
  class TextFilterDefinition < FilterDefinition
    class TextFilter < Filter
      def build_scope
        return Proc.new { |base| base } if empty?
        like_value = expression_value(value)
        operator = definition.options[:ignore_case] ? 'ILIKE' : 'LIKE'
        Proc.new {  |base| base.joins(definition.joins).where("#{definition.qualified_column_name} #{operator} ?", like_value ) }
      end

      def expression_value(term)
        if definition.options[:prefix]
         "#{term}%"
        else
         "%#{term}%"
        end
      end
    end

    def build_filter(search_instance, value)
      TextFilter.new(self, search_instance, value)
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
forty_facets-0.2.1 lib/forty_facets/filter/text_filter_definition.rb
forty_facets-0.2 lib/forty_facets/filter/text_filter_definition.rb
forty_facets-0.1.9.1 lib/forty_facets/filter/text_filter_definition.rb
forty_facets-0.1.9.0 lib/forty_facets/filter/text_filter_definition.rb
forty_facets-0.1.8.9 lib/forty_facets/filter/text_filter_definition.rb
forty_facets-0.1.8 lib/forty_facets/filter/text_filter_definition.rb
forty_facets-0.1.7 lib/forty_facets/filter/text_filter_definition.rb
forty_facets-0.1.6 lib/forty_facets/filter/text_filter_definition.rb
forty_facets-0.1.5 lib/forty_facets/filter/text_filter_definition.rb
forty_facets-0.1.4 lib/forty_facets/filter/text_filter_definition.rb
forty_facets-0.1.3 lib/forty_facets/filter/text_filter_definition.rb
forty_facets-0.1.2 lib/forty_facets/filter/text_filter_definition.rb
forty_facets-0.1.1 lib/forty_facets/filter/text_filter_definition.rb
forty_facets-0.1.0 lib/forty_facets/filter/text_filter_definition.rb
forty_facets-0.0.14 lib/forty_facets/filter/text_filter_definition.rb
forty_facets-0.0.13 lib/forty_facets/filter/text_filter_definition.rb
forty_facets-0.0.12 lib/forty_facets/filter/text_filter_definition.rb
forty_facets-0.0.11 lib/forty_facets/filter/text_filter_definition.rb