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
This filter requires specifying a
mapping argument, which is the path and name of a file containing the mappings to perform.
<analyzer> <charFilter class="solr.MappingCharFilterFactory" mapping="mapping-FoldToASCII.txt"/> <tokenizer ...> [...] </analyzer>
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) U+0008
"\b" => " "
tab (HT) U+0009
"\t" => ","
newline (LF) U+000A
"\n" => "<br>"
form feed (FF) U+000C
"\f" => "\n"
carriage return (CR) U+000D
"\r" => "/carriage-return/"
Unicode char referenced by the 4 hex digits U+XXXX
"\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.
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
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.
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
<span>will be removed.
Uppercase character entities like
ampare 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.
|if a<b then print a;|
|a<b A Alpha&Omega Ω|
<analyzer> <charFilter class="solr.HTMLStripCharFilterFactory"/> <tokenizer ...> [...] </analyzer>
This filter performs pre-tokenization Unicode normalization using ICU4J.
- A Unicode Normalization Form, one of
nfkc_cf. Default is
decompose. Default is
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).
<analyzer> <charFilter class="solr.ICUNormalizer2CharFilterFactory"/> <tokenizer ...> [...] </analyzer>
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:
<analyzer> <charFilter class="solr.PatternReplaceCharFilterFactory" pattern="([nN][oO]\.)\s*(\d+)" replacement="$1$2"/> <tokenizer ...> [...] </analyzer>
The table below presents examples of regex-based pattern replacement:
|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|
|abc=1234=5678||5678=abc=1234||Change the order of the groups.|