Search in sources :

Example 11 with StringMockResourceLoader

use of org.apache.lucene.analysis.util.StringMockResourceLoader in project lucene-solr by apache.

the class TestICUCollationField method setupSolrHome.

/**
   * Ugly: but what to do? We want to test custom sort, which reads rules in as a resource.
   * These are largish files, and jvm-specific (as our documentation says, you should always
   * look out for jvm differences with collation).
   * So it's preferable to create this file on-the-fly.
   */
public static String setupSolrHome() throws Exception {
    String tmpFile = createTempDir().toFile().getAbsolutePath();
    // make data and conf dirs
    new File(tmpFile + "/collection1", "data").mkdirs();
    File confDir = new File(tmpFile + "/collection1", "conf");
    confDir.mkdirs();
    // copy over configuration files
    FileUtils.copyFile(getFile("analysis-extras/solr/collection1/conf/solrconfig-icucollate.xml"), new File(confDir, "solrconfig.xml"));
    FileUtils.copyFile(getFile("analysis-extras/solr/collection1/conf/schema-icucollate.xml"), new File(confDir, "schema.xml"));
    // generate custom collation rules (DIN 5007-2), saving to customrules.dat
    RuleBasedCollator baseCollator = (RuleBasedCollator) Collator.getInstance(new ULocale("de", "DE"));
    String DIN5007_2_tailorings = "& ae , ä & AE , Ä" + "& oe , ö & OE , Ö" + "& ue , ü & UE , ü";
    RuleBasedCollator tailoredCollator = new RuleBasedCollator(baseCollator.getRules() + DIN5007_2_tailorings);
    String tailoredRules = tailoredCollator.getRules();
    final String osFileName = "customrules.dat";
    final FileOutputStream os = new FileOutputStream(new File(confDir, osFileName));
    IOUtils.write(tailoredRules, os, "UTF-8");
    os.close();
    final ResourceLoader loader;
    if (random().nextBoolean()) {
        loader = new StringMockResourceLoader(tailoredRules);
    } else {
        loader = new FilesystemResourceLoader(confDir.toPath());
    }
    final Collator readCollator = ICUCollationField.createFromRules(osFileName, loader);
    assertEquals(tailoredCollator, readCollator);
    return tmpFile;
}
Also used : ResourceLoader(org.apache.lucene.analysis.util.ResourceLoader) StringMockResourceLoader(org.apache.lucene.analysis.util.StringMockResourceLoader) FilesystemResourceLoader(org.apache.lucene.analysis.util.FilesystemResourceLoader) RuleBasedCollator(com.ibm.icu.text.RuleBasedCollator) FilesystemResourceLoader(org.apache.lucene.analysis.util.FilesystemResourceLoader) ULocale(com.ibm.icu.util.ULocale) FileOutputStream(java.io.FileOutputStream) File(java.io.File) StringMockResourceLoader(org.apache.lucene.analysis.util.StringMockResourceLoader) RuleBasedCollator(com.ibm.icu.text.RuleBasedCollator) Collator(com.ibm.icu.text.Collator)

Aggregations

StringMockResourceLoader (org.apache.lucene.analysis.util.StringMockResourceLoader)11 Reader (java.io.Reader)9 StringReader (java.io.StringReader)9 TokenStream (org.apache.lucene.analysis.TokenStream)9 Collator (com.ibm.icu.text.Collator)1 RuleBasedCollator (com.ibm.icu.text.RuleBasedCollator)1 ULocale (com.ibm.icu.util.ULocale)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AbstractAnalysisFactory (org.apache.lucene.analysis.util.AbstractAnalysisFactory)1 FilesystemResourceLoader (org.apache.lucene.analysis.util.FilesystemResourceLoader)1 ResourceLoader (org.apache.lucene.analysis.util.ResourceLoader)1 ResourceLoaderAware (org.apache.lucene.analysis.util.ResourceLoaderAware)1