def complete_key_value(field, token, val)
      key_name = token.sub(/^.*\./,"")
      key_klass = field.key_klass.where(field.key_field => key_name).first
      raise ScopedSearch::QueryNotSupported, "Field '#{key_name}' not recognized for searching!" if key_klass.nil?

      query = completer_scope(field)

      if field.key_klass != field.klass
        key   = field.key_klass.to_s.gsub(/.*::/,'').underscore.to_sym
        fk    = definition.reflection_by_name(field.klass, key).association_foreign_key.to_sym
        query = query.where(fk => key_klass.id)
      end

      query
        .where(value_conditions(field.quoted_field, val))
        .select("DISTINCT #{field.quoted_field}")
        .limit(20)
        .map(&field.field)
        .compact
        .map { |v| v.to_s =~ /\s/ ? "\"#{v}\"" : v }
    end
def complete_key_value(field, token, val)
      key_name = token.sub(/^.*\./,"")
      key_klass = field.key_klass.where(field.key_field => key_name).first
      raise ScopedSearch::QueryNotSupported, "Field '#{key_name}' not recognized for searching!" if key_klass.nil?

      query = completer_scope(field)

      if field.key_klass != field.klass
        key   = field.key_klass.to_s.gsub(/.*::/,'').underscore.to_sym
        fk    = definition.reflection_by_name(field.klass, key).association_foreign_key.to_sym
        query = query.where(fk => key_klass.id)
      end

      query
        .where(value_conditions(field.quoted_field, val))
        .select("DISTINCT #{field.quoted_field}")
        .limit(20)
        .map(&field.field)
        .compact
        .map { |v| v.to_s =~ /\s/ ? "\"#{v}\"" : v }
    end
complete values in a key-value schema