* Tests the analyzers defined on {@link Team}.
*
* @throws Exception in case the test fails.
*/
public void testAnalyzers() throws Exception {
SearchManager search = Search.getSearchManager(cache);
Analyzer analyzer = search.getSearchFactory().getAnalyzer( "standard_analyzer" );
String text = "This is just FOOBAR's";
Token[] tokens = AnalyzerUtils.tokensFromAnalysis( analyzer, "name", text );
assertTokensEqual( tokens, new String[] { "This", "is", "just", "FOOBAR's" } );
analyzer = search.getSearchFactory().getAnalyzer( "html_standard_analyzer" );
text = "This is <b>foo</b><i>bar's</i>";
tokens = AnalyzerUtils.tokensFromAnalysis( analyzer, "name", text );
assertTokensEqual( tokens, new String[] { "This", "is", "foobar's" } );
analyzer = search.getSearchFactory().getAnalyzer( "html_whitespace_analyzer" );
text = "This is <b>foo</b><i>bar's</i>";
tokens = AnalyzerUtils.tokensFromAnalysis( analyzer, "name", text );
assertTokensEqual( tokens, new String[] { "This", "is", "foobar's" } );
analyzer = search.getSearchFactory().getAnalyzer( "length_analyzer" );
text = "ab abc abcd abcde abcdef";
tokens = AnalyzerUtils.tokensFromAnalysis( analyzer, "name", text );
assertTokensEqual( tokens, new String[] { "abc", "abcd", "abcde" } );
analyzer = search.getSearchFactory().getAnalyzer( "length_analyzer" );
text = "ab abc abcd abcde abcdef";
tokens = AnalyzerUtils.tokensFromAnalysis( analyzer, "name", text );
assertTokensEqual( tokens, new String[] { "abc", "abcd", "abcde" } );
analyzer = search.getSearchFactory().getAnalyzer( "porter_analyzer" );
text = "bikes bikes biking";
tokens = AnalyzerUtils.tokensFromAnalysis( analyzer, "name", text );
assertTokensEqual( tokens, new String[] { "bike", "bike", "bike" } );
analyzer = search.getSearchFactory().getAnalyzer( "word_analyzer" );
text = "CamelCase";
tokens = AnalyzerUtils.tokensFromAnalysis( analyzer, "name", text );
assertTokensEqual( tokens, new String[] { "Camel", "Case" } );
analyzer = search.getSearchFactory().getAnalyzer( "synonym_analyzer" );
text = "ipod cosmos";
tokens = AnalyzerUtils.tokensFromAnalysis( analyzer, "name", text );
assertTokensEqual( tokens, new String[] { "ipod", "i-pod", "universe", "cosmos" } );
analyzer = search.getSearchFactory().getAnalyzer( "shingle_analyzer" );
text = "please divide this sentence into shingles";
tokens = AnalyzerUtils.tokensFromAnalysis( analyzer, "name", text );
assertTokensEqual(
tokens,
new String[] {
"please",
"please divide",
"divide",
"divide this",
"this",
"this sentence",
"sentence",
"sentence into",
"into",
"into shingles",
"shingles"
}
);
analyzer = search.getSearchFactory().getAnalyzer( "pattern_analyzer" );
text = "foo,bar";
tokens = AnalyzerUtils.tokensFromAnalysis( analyzer, "name", text );
assertTokensEqual( tokens, new String[] { "foo", "bar" } );
// CharStreamFactories test
analyzer = search.getSearchFactory().getAnalyzer( "mapping_char_analyzer" );
text = "CORA\u00C7\u00C3O DE MEL\u00C3O";
tokens = AnalyzerUtils.tokensFromAnalysis( analyzer, "name", text );
assertTokensEqual( tokens, new String[] { "CORACAO", "DE", "MELAO" } );
}