CharFilter is a component that pre-processes input characters.

CharFilters can be chained like Token Filters and placed in front of a Tokenizer. CharFilters can add, change, or remove characters while preserving the original character offsets to support features like highlighting.


This filter creates org.apache.lucene.analysis.MappingCharFilter, which can be used for changing one string to another (for example, for normalizing é to e.).

This filter requires specifying a mapping argument, which is the path and name of a file containing the mappings to perform.


  <charFilter class="solr.MappingCharFilterFactory" mapping="mapping-FoldToASCII.txt"/>
  <tokenizer ...>

Mapping file syntax:

  • Comment lines beginning with a hash mark (#), as well as blank lines, are ignored.

  • Each non-comment, non-blank line consists of a mapping of the form: "source" => "target"

    • Double-quoted source string, optional whitespace, an arrow (=>), optional whitespace, double-quoted target string.

  • Trailing comments on mapping lines are not allowed.

  • The source string must contain at least one character, but the target string may be empty.

  • The following character escape sequences are recognized within source and target strings:

    Escape Sequence Resulting Character (ECMA-48 alias) Unicode Character Example Mapping Line




    "\\" => "/"




    "\"and\"" => "'and'"


    backspace (BS)


    "\b" => " "


    tab (HT)


    "\t" => ","


    newline (LF)


    "\n" => "<br>"


    form feed (FF)


    "\f" => "\n"


    carriage return (CR)


    "\r" => "/carriage-return/"


    Unicode char referenced by the 4 hex digits


    "\uFEFF" => ""

    • A backslash followed by any other character is interpreted as if the character were present without the backslash.


This filter creates org.apache.solr.analysis.HTMLStripCharFilter. This CharFilter strips HTML from the input stream and passes the result to another CharFilter or a Tokenizer.

This filter:

  • Removes HTML/XML tags while preserving other content.

  • Removes attributes within tags and supports optional attribute quoting.

  • Removes XML processing instructions, such as: <?foo bar?>

  • Removes XML comments.

  • Removes XML elements starting with <!>.

  • Removes contents of <script> and <style> elements.

  • Handles XML comments inside these elements (normal comment processing will not always work).

  • Replaces numeric character entities references like &#65; or &#x7f; with the corresponding character.

  • The terminating ';' is optional if the entity reference at the end of the input; otherwise the terminating ';' is mandatory, to avoid false matches on something like "Alpha&Omega Corp".

  • Replaces all named character entity references with the corresponding character.

  • &nbsp; is replaced with a space instead of the 0xa0 character.

  • Newlines are substituted for block-level elements.

  • <CDATA> sections are recognized.

  • Inline tags, such as <b>, <i>, or <span> will be removed.

  • Uppercase character entities like quot, gt, lt and amp are recognized and handled as lowercase.

The input need not be an HTML document. The filter removes only constructs that look like HTML. If the input doesn’t include anything that looks like HTML, the filter won’t remove any input.

The table below presents examples of HTML stripping.

Input Output

my <a href="">link</a>

my link



hello<script><!-- f('<!--internal--></script>'); --></script>


if a<b then print a;

if a<b then print a;

hello <td height=22 nowrap align="left">


a<b &#65 Alpha&Omega Ω

a<b A Alpha&Omega Ω


  <charFilter class="solr.HTMLStripCharFilterFactory"/>
  <tokenizer ...>


This filter performs pre-tokenization Unicode normalization using ICU4J.



A Unicode Normalization Form, one of nfc, nfkc, nfkc_cf. Default is nfkc_cf.


Either compose or decompose. Default is compose. Use decompose with name="nfc" or name="nfkc" to get NFD or NFKD, respectively.


A UnicodeSet pattern. Codepoints outside the set are always left unchanged. Default is [] (the null set, no filtering - all codepoints are subject to normalization).


  <charFilter class="solr.ICUNormalizer2CharFilterFactory"/>
  <tokenizer ...>


This filter uses regular expressions to replace or change character patterns.



the regular expression pattern to apply to the incoming text.


the text to use to replace matching patterns.

You can configure this filter in schema.xml like this:

  <charFilter class="solr.PatternReplaceCharFilterFactory"
             pattern="([nN][oO]\.)\s*(\d+)" replacement="$1$2"/>
  <tokenizer ...>

The table below presents examples of regex-based pattern replacement:

Input Pattern Replacement Output Description

see-ing looking



see-ing look

Removes "ing" from the end of word.

see-ing looking



see-ing look

Same as above. 2nd parentheses can be omitted.

No.1 NO. no. 543



#1 NO. #543

Replace some string literals





Change the order of the groups.

Comments on this Page

We welcome feedback on Solr documentation. However, we cannot provide application support via comments. If you need help, please send a message to the Solr User mailing list.