|
45 | 45 | * <p>The second option is to specify collation rules as defined in the <a href="http://www.icu-project.org/userguide/Collate_Customization.html">
|
46 | 46 | * Collation customization</a> chapter in icu docs. The <tt>rules</tt> parameter can either embed the rules definition
|
47 | 47 | * in the settings or refer to an external location (preferable located under the <tt>config</tt> location, relative to it).
|
48 |
| - * |
49 |
| - * |
50 | 48 | */
|
51 | 49 | public class IcuCollationTokenFilterFactory extends AbstractTokenFilterFactory {
|
52 | 50 |
|
@@ -96,6 +94,81 @@ public IcuCollationTokenFilterFactory(Index index, @IndexSettings Settings index
|
96 | 94 | collator = Collator.getInstance();
|
97 | 95 | }
|
98 | 96 | }
|
| 97 | + |
| 98 | + // set the strength flag, otherwise it will be the default. |
| 99 | + String strength = settings.get("strength"); |
| 100 | + if (strength != null) { |
| 101 | + if (strength.equalsIgnoreCase("primary")) { |
| 102 | + collator.setStrength(Collator.PRIMARY); |
| 103 | + } else if (strength.equalsIgnoreCase("secondary")) { |
| 104 | + collator.setStrength(Collator.SECONDARY); |
| 105 | + } else if (strength.equalsIgnoreCase("tertiary")) { |
| 106 | + collator.setStrength(Collator.TERTIARY); |
| 107 | + } else if (strength.equalsIgnoreCase("quaternary")) { |
| 108 | + collator.setStrength(Collator.QUATERNARY); |
| 109 | + } else if (strength.equalsIgnoreCase("identical")) { |
| 110 | + collator.setStrength(Collator.IDENTICAL); |
| 111 | + } else { |
| 112 | + throw new ElasticSearchIllegalArgumentException("Invalid strength: " + strength); |
| 113 | + } |
| 114 | + } |
| 115 | + |
| 116 | + // set the decomposition flag, otherwise it will be the default. |
| 117 | + String decomposition = settings.get("decomposition"); |
| 118 | + if (decomposition != null) { |
| 119 | + if (decomposition.equalsIgnoreCase("no")) { |
| 120 | + collator.setDecomposition(Collator.NO_DECOMPOSITION); |
| 121 | + } else if (decomposition.equalsIgnoreCase("canonical")) { |
| 122 | + collator.setDecomposition(Collator.CANONICAL_DECOMPOSITION); |
| 123 | + } else { |
| 124 | + throw new ElasticSearchIllegalArgumentException("Invalid decomposition: " + decomposition); |
| 125 | + } |
| 126 | + } |
| 127 | + |
| 128 | + // expert options: concrete subclasses are always a RuleBasedCollator |
| 129 | + RuleBasedCollator rbc = (RuleBasedCollator) collator; |
| 130 | + String alternate = settings.get("alternate"); |
| 131 | + if (alternate != null) { |
| 132 | + if (alternate.equalsIgnoreCase("shifted")) { |
| 133 | + rbc.setAlternateHandlingShifted(true); |
| 134 | + } else if (alternate.equalsIgnoreCase("non-ignorable")) { |
| 135 | + rbc.setAlternateHandlingShifted(false); |
| 136 | + } else { |
| 137 | + throw new ElasticSearchIllegalArgumentException("Invalid alternate: " + alternate); |
| 138 | + } |
| 139 | + } |
| 140 | + |
| 141 | + Boolean caseLevel = settings.getAsBoolean("caseLevel", null); |
| 142 | + if (caseLevel != null) { |
| 143 | + rbc.setCaseLevel(caseLevel); |
| 144 | + } |
| 145 | + |
| 146 | + String caseFirst = settings.get("caseFirst"); |
| 147 | + if (caseFirst != null) { |
| 148 | + if (caseFirst.equalsIgnoreCase("lower")) { |
| 149 | + rbc.setLowerCaseFirst(true); |
| 150 | + } else if (caseFirst.equalsIgnoreCase("upper")) { |
| 151 | + rbc.setUpperCaseFirst(true); |
| 152 | + } else { |
| 153 | + throw new ElasticSearchIllegalArgumentException("Invalid caseFirst: " + caseFirst); |
| 154 | + } |
| 155 | + } |
| 156 | + |
| 157 | + Boolean numeric = settings.getAsBoolean("numeric", null); |
| 158 | + if (numeric != null) { |
| 159 | + rbc.setNumericCollation(numeric); |
| 160 | + } |
| 161 | + |
| 162 | + String variableTop = settings.get("variableTop"); |
| 163 | + if (variableTop != null) { |
| 164 | + rbc.setVariableTop(variableTop); |
| 165 | + } |
| 166 | + |
| 167 | + Boolean hiraganaQuaternaryMode = settings.getAsBoolean("hiraganaQuaternaryMode", null); |
| 168 | + if (hiraganaQuaternaryMode != null) { |
| 169 | + rbc.setHiraganaQuaternary(hiraganaQuaternaryMode); |
| 170 | + } |
| 171 | + |
99 | 172 | this.collator = collator;
|
100 | 173 | }
|
101 | 174 |
|
|
0 commit comments