package gw.solr.mapper.query

uses java.lang.Character


/**
 * Simple search value encoder that converts "special" characters to
 * whitespace and then compresses each whitespace block into a single
 * '+' sign (so edismax performs distinct term queries on the implied
 * terms entered by the user).
 */
@ReadOnly
class PhraseEncoder extends AbstractEncoder {

  /**
   * Encode whitespace and unsupported characters as '+' for multi-term edismax queries.
   */
  public final static var ENCODED_CHAR : char = '+'
  
  override function isSearchable(c : char) : boolean {
    return Character.isLetterOrDigit(c) ||
        // Ascii symbols that could be searchable (e.g not wordbreaks)
        // see defn of MidNumLet & MidLetter from table 3 in http://unicode.org/reports/tr29/#Word_Boundaries
        c == HYPHEN || c == PERIOD || 
        // Unclear if allowing searching on ' (apostrophe) is a good idea
        // c == APOSTROPHE ||
        Character.isLowSurrogate(c) ||
        Character.isHighSurrogate(c)
  }

  override property get EncodedChar() : char {
    return ENCODED_CHAR
  }

}

