/* * Test secondary strength, for english case is not significant. */ //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void testSecondaryStrength() throws Exception public virtual void testSecondaryStrength() { string upperCase = "TESTING"; string lowerCase = "testing"; TokenFilterFactory factory = tokenFilterFactory("CollationKey", "language", "en", "strength", "secondary", "decomposition", "no"); TokenStream tsUpper = factory.create(new MockTokenizer(new StringReader(upperCase), MockTokenizer.KEYWORD, false)); TokenStream tsLower = factory.create(new MockTokenizer(new StringReader(lowerCase), MockTokenizer.KEYWORD, false)); assertCollatesToSame(tsUpper, tsLower); }
/* * Test usage of the K decomposition option for unicode normalization. * This works even with identical strength. */ //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void testFullDecomposition() throws Exception public virtual void testFullDecomposition() { string fullWidth = "Testing"; string halfWidth = "Testing"; TokenFilterFactory factory = tokenFilterFactory("CollationKey", "language", "zh", "strength", "identical", "decomposition", "full"); TokenStream tsFull = factory.create(new MockTokenizer(new StringReader(fullWidth), MockTokenizer.KEYWORD, false)); TokenStream tsHalf = factory.create(new MockTokenizer(new StringReader(halfWidth), MockTokenizer.KEYWORD, false)); assertCollatesToSame(tsFull, tsHalf); }
/* * Test usage of the decomposition option for unicode normalization. */ //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void testNormalization() throws Exception public virtual void testNormalization() { string turkishUpperCase = "I W\u0049\u0307LL USE TURKİSH CASING"; string turkishLowerCase = "ı will use turkish casıng"; TokenFilterFactory factory = tokenFilterFactory("CollationKey", "language", "tr", "strength", "primary", "decomposition", "canonical"); TokenStream tsUpper = factory.create(new MockTokenizer(new StringReader(turkishUpperCase), MockTokenizer.KEYWORD, false)); TokenStream tsLower = factory.create(new MockTokenizer(new StringReader(turkishLowerCase), MockTokenizer.KEYWORD, false)); assertCollatesToSame(tsUpper, tsLower); }
/* * Turkish has some funny casing. * This test shows how you can solve this kind of thing easily with collation. * Instead of using LowerCaseFilter, use a turkish collator with primary strength. * Then things will sort and match correctly. */ //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void testBasicUsage() throws Exception public virtual void testBasicUsage() { string turkishUpperCase = "I WİLL USE TURKİSH CASING"; string turkishLowerCase = "ı will use turkish casıng"; TokenFilterFactory factory = tokenFilterFactory("CollationKey", "language", "tr", "strength", "primary"); TokenStream tsUpper = factory.create(new MockTokenizer(new StringReader(turkishUpperCase), MockTokenizer.KEYWORD, false)); TokenStream tsLower = factory.create(new MockTokenizer(new StringReader(turkishLowerCase), MockTokenizer.KEYWORD, false)); assertCollatesToSame(tsUpper, tsLower); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void testCreationWithWhiteList() throws Exception public virtual void testCreationWithWhiteList() { TokenFilterFactory factory = tokenFilterFactory("Type", "types", "stoptypes-1.txt, stoptypes-2.txt", "enablePositionIncrements", "true", "useWhitelist", "true"); NumericTokenStream input = new NumericTokenStream(); input.IntValue = 123; factory.create(input); }
/// <summary> /// checks for synonyms of "second" in synonyms-wordnet.txt </summary> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private void checkWordnetSynonyms(org.apache.lucene.analysis.util.TokenFilterFactory factory) throws Exception private void checkWordnetSynonyms(TokenFilterFactory factory) { Reader reader = new StringReader("second"); TokenStream stream = new MockTokenizer(reader, MockTokenizer.WHITESPACE, false); stream = factory.create(stream); assertTrue(stream is SynonymFilter); assertTokenStreamContents(stream, new string[] { "second", "2nd", "two" }, new int[] { 1, 0, 0 }); }
/// <summary> /// checks for synonyms of "GB" in synonyms.txt </summary> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private void checkSolrSynonyms(org.apache.lucene.analysis.util.TokenFilterFactory factory) throws Exception private void checkSolrSynonyms(TokenFilterFactory factory) { Reader reader = new StringReader("GB"); TokenStream stream = new MockTokenizer(reader, MockTokenizer.WHITESPACE, false); stream = factory.create(stream); assertTrue(stream is SynonymFilter); assertTokenStreamContents(stream, new string[] { "GB", "gib", "gigabyte", "gigabytes" }, new int[] { 1, 0, 0, 0 }); }
protected internal override TokenStreamComponents createComponents(string fieldName, Reader reader) { Tokenizer tf = tokenizer.create(reader); if (tokenfilter != null) { return(new TokenStreamComponents(tf, tokenfilter.create(tf))); } else { return(new TokenStreamComponents(tf)); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void test() throws Exception public virtual void test() { IList <Type> analysisClasses = new List <Type>(); ((List <Type>)analysisClasses).AddRange(TestRandomChains.getClassesForPackage("org.apache.lucene.analysis")); ((List <Type>)analysisClasses).AddRange(TestRandomChains.getClassesForPackage("org.apache.lucene.collation")); foreach (Class c in analysisClasses) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int modifiers = c.getModifiers(); int modifiers = c.Modifiers; if (Modifier.isAbstract(modifiers) || !Modifier.isPublic(modifiers) || c.Synthetic || c.AnonymousClass || c.MemberClass || c.Interface || testComponents.Contains(c) || crazyComponents.Contains(c) || oddlyNamedComponents.Contains(c) || deprecatedDuplicatedComponents.Contains(c) || c.isAnnotationPresent(typeof(Deprecated)) || !(c.IsSubclassOf(typeof(Tokenizer)) || c.IsSubclassOf(typeof(TokenFilter)) || c.IsSubclassOf(typeof(CharFilter)))) { // deprecated ones are typically back compat hacks // don't waste time with abstract classes continue; } IDictionary <string, string> args = new Dictionary <string, string>(); args["luceneMatchVersion"] = TEST_VERSION_CURRENT.ToString(); if (c.IsSubclassOf(typeof(Tokenizer))) { string clazzName = c.SimpleName; assertTrue(clazzName.EndsWith("Tokenizer", StringComparison.Ordinal)); string simpleName = clazzName.Substring(0, clazzName.Length - 9); assertNotNull(TokenizerFactory.lookupClass(simpleName)); TokenizerFactory instance = null; try { instance = TokenizerFactory.forName(simpleName, args); assertNotNull(instance); if (instance is ResourceLoaderAware) { ((ResourceLoaderAware)instance).inform(loader); } assertSame(c, instance.create(new StringReader("")).GetType()); } catch (System.ArgumentException e) { if (e.InnerException is NoSuchMethodException) { // there is no corresponding ctor available throw e; } // TODO: For now pass because some factories have not yet a default config that always works } } else if (c.IsSubclassOf(typeof(TokenFilter))) { string clazzName = c.SimpleName; assertTrue(clazzName.EndsWith("Filter", StringComparison.Ordinal)); string simpleName = clazzName.Substring(0, clazzName.Length - (clazzName.EndsWith("TokenFilter", StringComparison.Ordinal) ? 11 : 6)); assertNotNull(TokenFilterFactory.lookupClass(simpleName)); TokenFilterFactory instance = null; try { instance = TokenFilterFactory.forName(simpleName, args); assertNotNull(instance); if (instance is ResourceLoaderAware) { ((ResourceLoaderAware)instance).inform(loader); } //JAVA TO C# CONVERTER TODO TASK: Java wildcard generics are not converted to .NET: //ORIGINAL LINE: Class<? extends org.apache.lucene.analysis.TokenStream> createdClazz = instance.create(new KeywordTokenizer(new java.io.StringReader(""))).getClass(); Type <?> createdClazz = instance.create(new KeywordTokenizer(new StringReader(""))).GetType(); // only check instance if factory have wrapped at all! if (typeof(KeywordTokenizer) != createdClazz) { assertSame(c, createdClazz); } } catch (System.ArgumentException e) { if (e.InnerException is NoSuchMethodException) { // there is no corresponding ctor available throw e; } // TODO: For now pass because some factories have not yet a default config that always works } } else if (c.IsSubclassOf(typeof(CharFilter))) { string clazzName = c.SimpleName; assertTrue(clazzName.EndsWith("CharFilter", StringComparison.Ordinal)); string simpleName = clazzName.Substring(0, clazzName.Length - 10); assertNotNull(CharFilterFactory.lookupClass(simpleName)); CharFilterFactory instance = null; try { instance = CharFilterFactory.forName(simpleName, args); assertNotNull(instance); if (instance is ResourceLoaderAware) { ((ResourceLoaderAware)instance).inform(loader); } //JAVA TO C# CONVERTER TODO TASK: Java wildcard generics are not converted to .NET: //ORIGINAL LINE: Class<? extends java.io.Reader> createdClazz = instance.create(new java.io.StringReader("")).getClass(); Type <?> createdClazz = instance.create(new StringReader("")).GetType(); // only check instance if factory have wrapped at all! if (typeof(StringReader) != createdClazz) { assertSame(c, createdClazz); } } catch (System.ArgumentException e) { if (e.InnerException is NoSuchMethodException) { // there is no corresponding ctor available throw e; } // TODO: For now pass because some factories have not yet a default config that always works } } } }