Search in sources :

Example 11 with RuleBasedCollator

use of java.text.RuleBasedCollator in project lucene-solr by apache.

the class CollationField method createFromRules.

/**
   * Read custom rules from a file, and create a RuleBasedCollator
   * The file cannot support comments, as # might be in the rules!
   */
private Collator createFromRules(String fileName, ResourceLoader loader) {
    InputStream input = null;
    try {
        input = loader.openResource(fileName);
        String rules = IOUtils.toString(input, "UTF-8");
        return new RuleBasedCollator(rules);
    } catch (IOException | ParseException e) {
        // io error or invalid rules
        throw new RuntimeException(e);
    } finally {
        IOUtils.closeQuietly(input);
    }
}
Also used : RuleBasedCollator(java.text.RuleBasedCollator) InputStream(java.io.InputStream) IOException(java.io.IOException) ParseException(java.text.ParseException)

Aggregations

RuleBasedCollator (java.text.RuleBasedCollator)11 Collator (java.text.Collator)3 ParseException (java.text.ParseException)3 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 Locale (java.util.Locale)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 CharacterIterator (java.text.CharacterIterator)1 CollationElementIterator (java.text.CollationElementIterator)1 CollationKey (java.text.CollationKey)1 StringCharacterIterator (java.text.StringCharacterIterator)1 CollationKeyAnalyzer (org.apache.lucene.collation.CollationKeyAnalyzer)1 SolrException (org.apache.solr.common.SolrException)1