How do I write my own Analyzer?

Otis Gospodnetic

Here is an example:

public class MyAnalyzer extends Analyzer
{
    private static final Analyzer STANDARD = new StandardAnalyzer();

    public TokenStream tokenStream(String field, final Reader reader) 
    {
        // do not tokenize field called 'element'
        if ("element".equals(field))
        {
            return new CharTokenizer(reader)
            {
                protected boolean isTokenChar(char c)
                {
                    return true;
                }
            };
        }
        else
        {
            // use standard analyzer
            return STANDARD.tokenStream(field, reader);
        }
    }
}
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact