Search in sources :

Example 1 with Encoder

use of org.apache.commons.codec.Encoder in project lucene-solr by apache.

the class TestPhoneticFilter method testRandomStrings.

/** blast some random strings through the analyzer */
public void testRandomStrings() throws IOException {
    Encoder[] encoders = new Encoder[] { new Metaphone(), new DoubleMetaphone(), new Soundex(), new RefinedSoundex(), new Caverphone2() };
    for (final Encoder e : encoders) {
        Analyzer a = new Analyzer() {

            @Override
            protected TokenStreamComponents createComponents(String fieldName) {
                Tokenizer tokenizer = new MockTokenizer(MockTokenizer.WHITESPACE, false);
                return new TokenStreamComponents(tokenizer, new PhoneticFilter(tokenizer, e, false));
            }
        };
        checkRandomData(random(), a, 1000 * RANDOM_MULTIPLIER);
        a.close();
        Analyzer b = new Analyzer() {

            @Override
            protected TokenStreamComponents createComponents(String fieldName) {
                Tokenizer tokenizer = new MockTokenizer(MockTokenizer.WHITESPACE, false);
                return new TokenStreamComponents(tokenizer, new PhoneticFilter(tokenizer, e, false));
            }
        };
        checkRandomData(random(), b, 1000 * RANDOM_MULTIPLIER);
        b.close();
    }
}
Also used : RefinedSoundex(org.apache.commons.codec.language.RefinedSoundex) DoubleMetaphone(org.apache.commons.codec.language.DoubleMetaphone) Metaphone(org.apache.commons.codec.language.Metaphone) Caverphone2(org.apache.commons.codec.language.Caverphone2) Analyzer(org.apache.lucene.analysis.Analyzer) MockTokenizer(org.apache.lucene.analysis.MockTokenizer) RefinedSoundex(org.apache.commons.codec.language.RefinedSoundex) Soundex(org.apache.commons.codec.language.Soundex) DoubleMetaphone(org.apache.commons.codec.language.DoubleMetaphone) Encoder(org.apache.commons.codec.Encoder) Tokenizer(org.apache.lucene.analysis.Tokenizer) MockTokenizer(org.apache.lucene.analysis.MockTokenizer) KeywordTokenizer(org.apache.lucene.analysis.core.KeywordTokenizer)

Example 2 with Encoder

use of org.apache.commons.codec.Encoder in project lucene-solr by apache.

the class TestPhoneticFilter method testEmptyTerm.

public void testEmptyTerm() throws IOException {
    Encoder[] encoders = new Encoder[] { new Metaphone(), new DoubleMetaphone(), new Soundex(), new RefinedSoundex(), new Caverphone2() };
    for (final Encoder e : encoders) {
        Analyzer a = new Analyzer() {

            @Override
            protected TokenStreamComponents createComponents(String fieldName) {
                Tokenizer tokenizer = new KeywordTokenizer();
                return new TokenStreamComponents(tokenizer, new PhoneticFilter(tokenizer, e, random().nextBoolean()));
            }
        };
        checkOneTerm(a, "", "");
        a.close();
    }
}
Also used : RefinedSoundex(org.apache.commons.codec.language.RefinedSoundex) DoubleMetaphone(org.apache.commons.codec.language.DoubleMetaphone) Metaphone(org.apache.commons.codec.language.Metaphone) Caverphone2(org.apache.commons.codec.language.Caverphone2) Analyzer(org.apache.lucene.analysis.Analyzer) KeywordTokenizer(org.apache.lucene.analysis.core.KeywordTokenizer) RefinedSoundex(org.apache.commons.codec.language.RefinedSoundex) Soundex(org.apache.commons.codec.language.Soundex) DoubleMetaphone(org.apache.commons.codec.language.DoubleMetaphone) Encoder(org.apache.commons.codec.Encoder) Tokenizer(org.apache.lucene.analysis.Tokenizer) MockTokenizer(org.apache.lucene.analysis.MockTokenizer) KeywordTokenizer(org.apache.lucene.analysis.core.KeywordTokenizer)

Aggregations

Encoder (org.apache.commons.codec.Encoder)2 Caverphone2 (org.apache.commons.codec.language.Caverphone2)2 DoubleMetaphone (org.apache.commons.codec.language.DoubleMetaphone)2 Metaphone (org.apache.commons.codec.language.Metaphone)2 RefinedSoundex (org.apache.commons.codec.language.RefinedSoundex)2 Soundex (org.apache.commons.codec.language.Soundex)2 Analyzer (org.apache.lucene.analysis.Analyzer)2 MockTokenizer (org.apache.lucene.analysis.MockTokenizer)2 Tokenizer (org.apache.lucene.analysis.Tokenizer)2 KeywordTokenizer (org.apache.lucene.analysis.core.KeywordTokenizer)2