This analyzer is used to facilitate scenarios where different fields require different analysis techniques. Use the Map argument in #PerFieldAnalyzerWrapper(Analyzer, java.util.Map) to add non-default analyzers for fields.

Example usage:

 {@code Map analyzerPerField = new HashMap<>(); analyzerPerField.put("firstname", new KeywordAnalyzer()); analyzerPerField.put("lastname", new KeywordAnalyzer()); PerFieldAnalyzerWrapper aWrapper = new PerFieldAnalyzerWrapper(new StandardAnalyzer(version), analyzerPerField); } 

In this example, StandardAnalyzer will be used for all fields except "firstname" and "lastname", for which KeywordAnalyzer will be used.

A PerFieldAnalyzerWrapper can be used like any other analyzer, for both indexing and query parsing.

Inheritance: AnalyzerWrapper
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        //ORIGINAL LINE: public void testCharFilters() throws Exception
        public virtual void testCharFilters()
        {
            Analyzer a = new AnalyzerAnonymousInnerClassHelper(this);
            assertAnalyzesTo(a, "ab", new string[] {"aab"}, new int[] {0}, new int[] {2});

            // now wrap in PFAW
            PerFieldAnalyzerWrapper p = new PerFieldAnalyzerWrapper(a, System.Linq.Enumerable.Empty<string, Analyzer>());

            assertAnalyzesTo(p, "ab", new string[] {"aab"}, new int[] {0}, new int[] {2});
        }
Ejemplo n.º 2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void testCharFilters() throws Exception
        public virtual void testCharFilters()
        {
            Analyzer a = new AnalyzerAnonymousInnerClassHelper(this);

            assertAnalyzesTo(a, "ab", new string[] { "aab" }, new int[] { 0 }, new int[] { 2 });

            // now wrap in PFAW
            PerFieldAnalyzerWrapper p = new PerFieldAnalyzerWrapper(a, System.Linq.Enumerable.Empty <string, Analyzer>());

            assertAnalyzesTo(p, "ab", new string[] { "aab" }, new int[] { 0 }, new int[] { 2 });
        }
Ejemplo n.º 3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void testPerField() throws Exception
        public virtual void testPerField()
        {
            string text = "Qwerty";

            IDictionary <string, Analyzer> analyzerPerField = new Dictionary <string, Analyzer>();

            analyzerPerField["special"] = new SimpleAnalyzer(TEST_VERSION_CURRENT);

            PerFieldAnalyzerWrapper analyzer = new PerFieldAnalyzerWrapper(new WhitespaceAnalyzer(TEST_VERSION_CURRENT), analyzerPerField);

            TokenStream tokenStream = analyzer.tokenStream("field", text);

            try
            {
                CharTermAttribute termAtt = tokenStream.getAttribute(typeof(CharTermAttribute));
                tokenStream.reset();

                assertTrue(tokenStream.incrementToken());
                assertEquals("WhitespaceAnalyzer does not lowercase", "Qwerty", termAtt.ToString());
                assertFalse(tokenStream.incrementToken());
                tokenStream.end();
            }
            finally
            {
                IOUtils.closeWhileHandlingException(tokenStream);
            }

            tokenStream = analyzer.tokenStream("special", text);
            try
            {
                CharTermAttribute termAtt = tokenStream.getAttribute(typeof(CharTermAttribute));
                tokenStream.reset();

                assertTrue(tokenStream.incrementToken());
                assertEquals("SimpleAnalyzer lowercases", "qwerty", termAtt.ToString());
                assertFalse(tokenStream.incrementToken());
                tokenStream.end();
            }
            finally
            {
                IOUtils.closeWhileHandlingException(tokenStream);
            }
        }
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        //ORIGINAL LINE: public void testPerField() throws Exception
        public virtual void testPerField()
        {
            string text = "Qwerty";

            IDictionary<string, Analyzer> analyzerPerField = new Dictionary<string, Analyzer>();
            analyzerPerField["special"] = new SimpleAnalyzer(TEST_VERSION_CURRENT);

            PerFieldAnalyzerWrapper analyzer = new PerFieldAnalyzerWrapper(new WhitespaceAnalyzer(TEST_VERSION_CURRENT), analyzerPerField);

            TokenStream tokenStream = analyzer.tokenStream("field", text);
            try
            {
              CharTermAttribute termAtt = tokenStream.getAttribute(typeof(CharTermAttribute));
              tokenStream.reset();

              assertTrue(tokenStream.incrementToken());
              assertEquals("WhitespaceAnalyzer does not lowercase", "Qwerty", termAtt.ToString());
              assertFalse(tokenStream.incrementToken());
              tokenStream.end();
            }
            finally
            {
              IOUtils.closeWhileHandlingException(tokenStream);
            }

            tokenStream = analyzer.tokenStream("special", text);
            try
            {
              CharTermAttribute termAtt = tokenStream.getAttribute(typeof(CharTermAttribute));
              tokenStream.reset();

              assertTrue(tokenStream.incrementToken());
              assertEquals("SimpleAnalyzer lowercases", "qwerty", termAtt.ToString());
              assertFalse(tokenStream.incrementToken());
              tokenStream.end();
            }
            finally
            {
              IOUtils.closeWhileHandlingException(tokenStream);
            }
        }