       value:      $option[0].value
       selected:   false
       disabled:   false
-      match_type: if append then null else 0
+      match_type: if append then null else -1
 
     if append
       @all_options.push chosen_option


    return null

  apply_filter: (value) ->
    @reset_filter()

    if (value = $.trim(value))
      scores = [
        @all_options.length * 12, @all_options.length * 9
        @all_options.length * 6, @all_options.length * 3
        @all_options.length
      ]

      exact_query = value.toLowerCase()
      query = exact_query.replace(Parser.escape_exp, "\\$&").split(" ")

      expressions_collection = $.map(query, (word, index) ->
        return [[
          new RegExp("^#{word}$", "i"),
          new RegExp("^#{word}", "i")
          new RegExp("#{word}$", "i"),
          new RegExp(word, "i")
        ]]
      )

      for option in @all_options
        if option.label.toLowerCase() is exact_query
          option.match_type = 0
        else
          option.match_type = null

        words = option.label.split(" ")

        for word in words
          for expressions in expressions_collection
            for expression, index in expressions
              if word.match(expression)
                if option.match_type is null
                  option.match_type = index + 1

                option.score += scores[option.match_type]
                break
              else if index is expressions.length - 1
                option.score -= 1

    @order()
    return @

  reset_filter: ->
    option.score = option.index * -1 for option in @all_options
    return @

  order: ->
    @all_options = @all_options.sort (a, b) ->
      if a.score > b.score then -1 else if a.score < b.score then 1 else 0

    @available_options = []

    for option in @all_options
      if not option.blank
        @available_options.push(option)

    return @

  default_parser: (attrs) ->
    value: attrs.value


    @chosen.$target.find("option").each (index, option) =>
      if option.parentNode.nodeName is "OPTGROUP"
        if group_label != option.parentNode.label
          group_label = option.parentNode.label
          group = $("<li />", class: "chosen-group", text: group_label)
          group.group_id = group_id
          group_id += 1
      else
        group = null

      classes = "chosen-option"
      classes += " group"    if group
      classes += " selected" if option.selected
      classes += " disabled" if option.disabled

