Sha256: 5a1234a02674add822cc906ae3dfef9458f26d61ef213f5729f59a13fbf726a0

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

# -*- encoding : utf-8 -*-
require 'search/conditions/abstract'

module RademadeAdmin
  module Search
    module Conditions
      class Autocomplete < Abstract

        protected

        def where
          @where_conditions = RademadeAdmin::Search::Part::Where.new(:and)
          append_query_condition
          append_search_params
          append_ids_params
          @where_conditions
        end

        def limit
          10
        end

        private

        def append_query_condition
          if @params[:q].present?
            query_where = RademadeAdmin::Search::Part::Where.new(:or)
            @data_items.filter_fields.each do |field|
              query_where.add(field, /#{@params[:q]}/i)
            end
            @where_conditions.sub_add(query_where)
          end
        end

        def append_search_params
          if @params[:search].present?
            @params[:search].each do |key, value|
              @where_conditions.add(key.to_sym, value) if @data_items.origin_fields.include? key.to_s
            end
          end
        end

        def append_ids_params
          if @params[:ids].present?
            @where_conditions.add(@data_items.primary_field.name, @params[:ids])
          end
        end

      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rademade_admin-0.1.0 app/services/search/conditions/autocomplete.rb