Search in sources :

Example 1 with KeywordAttribute

use of org.apache.lucene.analysis.tokenattributes.KeywordAttribute in project lucene-solr by apache.

the class TestBeiderMorseFilter method testCustomAttribute.

public void testCustomAttribute() throws IOException {
    TokenStream stream = new MockTokenizer(MockTokenizer.KEYWORD, false);
    ((Tokenizer) stream).setReader(new StringReader("D'Angelo"));
    stream = new PatternKeywordMarkerFilter(stream, Pattern.compile(".*"));
    stream = new BeiderMorseFilter(stream, new PhoneticEngine(NameType.GENERIC, RuleType.EXACT, true));
    KeywordAttribute keyAtt = stream.addAttribute(KeywordAttribute.class);
    stream.reset();
    int i = 0;
    while (stream.incrementToken()) {
        assertTrue(keyAtt.isKeyword());
        i++;
    }
    assertEquals(12, i);
    stream.end();
    stream.close();
}
Also used : MockTokenizer(org.apache.lucene.analysis.MockTokenizer) PhoneticEngine(org.apache.commons.codec.language.bm.PhoneticEngine) TokenStream(org.apache.lucene.analysis.TokenStream) KeywordAttribute(org.apache.lucene.analysis.tokenattributes.KeywordAttribute) StringReader(java.io.StringReader) Tokenizer(org.apache.lucene.analysis.Tokenizer) MockTokenizer(org.apache.lucene.analysis.MockTokenizer) KeywordTokenizer(org.apache.lucene.analysis.core.KeywordTokenizer) PatternKeywordMarkerFilter(org.apache.lucene.analysis.miscellaneous.PatternKeywordMarkerFilter)

Aggregations

StringReader (java.io.StringReader)1 PhoneticEngine (org.apache.commons.codec.language.bm.PhoneticEngine)1 MockTokenizer (org.apache.lucene.analysis.MockTokenizer)1 TokenStream (org.apache.lucene.analysis.TokenStream)1 Tokenizer (org.apache.lucene.analysis.Tokenizer)1 KeywordTokenizer (org.apache.lucene.analysis.core.KeywordTokenizer)1 PatternKeywordMarkerFilter (org.apache.lucene.analysis.miscellaneous.PatternKeywordMarkerFilter)1 KeywordAttribute (org.apache.lucene.analysis.tokenattributes.KeywordAttribute)1