Last active
September 16, 2022 09:21
-
-
Save peaeater/0b3473e7457dbd4b527e to your computer and use it in GitHub Desktop.
Alphanumeric field type for Solr which lowercases, removes leading articles, and forces numbers to sort numerically.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<fieldType name="alphaNumericSort" class="solr.TextField" sortMissingLast="false" omitNorms="true"> | |
<analyzer> | |
<!-- KeywordTokenizer does no actual tokenizing, so the entire | |
input string is preserved as a single token | |
--> | |
<tokenizer class="solr.KeywordTokenizerFactory"/> | |
<!-- The LowerCase TokenFilter does what you expect, which can be | |
when you want your sorting to be case insensitive | |
--> | |
<filter class="solr.LowerCaseFilterFactory" /> | |
<!-- The TrimFilter removes any leading or trailing whitespace --> | |
<filter class="solr.TrimFilterFactory" /> | |
<!-- Remove leading articles --> | |
<filter class="solr.PatternReplaceFilterFactory" | |
pattern="^(a |the |les |la |le |l'|de la |du |des )" replacement="" replace="all" | |
/> | |
<!-- Left-pad numbers with zeroes --> | |
<filter class="solr.PatternReplaceFilterFactory" | |
pattern="(\d+)" replacement="00000$1" replace="all" | |
/> | |
<!-- Left-trim zeroes to produce 6 digit numbers --> | |
<filter class="solr.PatternReplaceFilterFactory" | |
pattern="0*([0-9]{6,})" replacement="$1" replace="all" | |
/> | |
<!-- Remove all but alphanumeric characters --> | |
<filter class="solr.PatternReplaceFilterFactory" | |
pattern="([^a-z0-9])" replacement="" replace="all" | |
/> | |
</analyzer> | |
</fieldType> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment