Search in sources :

Example 91 with Analyzer

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

the class TestSynonymGraphFilter method getFlattenAnalyzer.

/** Appends FlattenGraphFilter too */
private Analyzer getFlattenAnalyzer(SynonymMap.Builder b, boolean ignoreCase) throws IOException {
    final SynonymMap map = b.build();
    return new Analyzer() {

        @Override
        protected TokenStreamComponents createComponents(String fieldName) {
            Tokenizer tokenizer = new MockTokenizer(MockTokenizer.WHITESPACE, true);
            // Make a local variable so testRandomHuge doesn't share it across threads!
            SynonymGraphFilter synFilter = new SynonymGraphFilter(tokenizer, map, ignoreCase);
            FlattenGraphFilter flattenFilter = new FlattenGraphFilter(synFilter);
            TestSynonymGraphFilter.this.synFilter = synFilter;
            TestSynonymGraphFilter.this.flattenFilter = flattenFilter;
            return new TokenStreamComponents(tokenizer, flattenFilter);
        }
    };
}
Also used : MockTokenizer(org.apache.lucene.analysis.MockTokenizer) Analyzer(org.apache.lucene.analysis.Analyzer) MockAnalyzer(org.apache.lucene.analysis.MockAnalyzer) FlattenGraphFilter(org.apache.lucene.analysis.core.FlattenGraphFilter) Tokenizer(org.apache.lucene.analysis.Tokenizer) MockTokenizer(org.apache.lucene.analysis.MockTokenizer)

Example 92 with Analyzer

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

the class TestSynonymGraphFilter method testBufferedFinish1.

public void testBufferedFinish1() throws Exception {
    SynonymMap.Builder b = new SynonymMap.Builder();
    add(b, "a b c", "m n o", false);
    Analyzer a = getAnalyzer(b, true);
    assertAnalyzesTo(a, "c a b", new String[] { "c", "a", "b" }, new int[] { 0, 2, 4 }, new int[] { 1, 3, 5 }, new String[] { "word", "word", "word" }, new int[] { 1, 1, 1 }, new int[] { 1, 1, 1 });
    a.close();
}
Also used : CharsRefBuilder(org.apache.lucene.util.CharsRefBuilder) IntsRefBuilder(org.apache.lucene.util.IntsRefBuilder) Analyzer(org.apache.lucene.analysis.Analyzer) MockAnalyzer(org.apache.lucene.analysis.MockAnalyzer)

Example 93 with Analyzer

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

the class TestSynonymGraphFilter method testSynAtEnd.

public void testSynAtEnd() throws Exception {
    SynonymMap.Builder b = new SynonymMap.Builder();
    add(b, "a b", "x", true);
    Analyzer a = getAnalyzer(b, true);
    assertAnalyzesTo(a, "c d e a b", new String[] { "c", "d", "e", "x", "a", "b" }, new int[] { 0, 2, 4, 6, 6, 8 }, new int[] { 1, 3, 5, 9, 7, 9 }, new String[] { "word", "word", "word", "SYNONYM", "word", "word" }, new int[] { 1, 1, 1, 1, 0, 1 }, new int[] { 1, 1, 1, 2, 1, 1 });
    a.close();
}
Also used : CharsRefBuilder(org.apache.lucene.util.CharsRefBuilder) IntsRefBuilder(org.apache.lucene.util.IntsRefBuilder) Analyzer(org.apache.lucene.analysis.Analyzer) MockAnalyzer(org.apache.lucene.analysis.MockAnalyzer)

Example 94 with Analyzer

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

the class TestSynonymGraphFilter method testDoNotIgnoreCase.

public void testDoNotIgnoreCase() throws Exception {
    SynonymMap.Builder b = new SynonymMap.Builder();
    add(b, "a b", "x y", false);
    add(b, "a b", "m n o", false);
    Analyzer a = getAnalyzer(b, false);
    assertAnalyzesTo(a, "c A B D", new String[] { "c", "A", "B", "D" }, new int[] { 0, 2, 4, 6 }, new int[] { 1, 3, 5, 7 }, new String[] { "word", "word", "word", "word" }, new int[] { 1, 1, 1, 1 }, new int[] { 1, 1, 1, 1 });
    a.close();
}
Also used : CharsRefBuilder(org.apache.lucene.util.CharsRefBuilder) IntsRefBuilder(org.apache.lucene.util.IntsRefBuilder) Analyzer(org.apache.lucene.analysis.Analyzer) MockAnalyzer(org.apache.lucene.analysis.MockAnalyzer)

Example 95 with Analyzer

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

the class TestSynonymGraphFilter method testBasicNoKeepOrigTwoOutputs.

public void testBasicNoKeepOrigTwoOutputs() throws Exception {
    SynonymMap.Builder b = new SynonymMap.Builder();
    add(b, "a b", "x y", false);
    add(b, "a b", "m n o", false);
    Analyzer a = getAnalyzer(b, true);
    assertAnalyzesTo(a, "c a b d", new String[] { "c", "x", "m", "y", "n", "o", "d" }, new int[] { 0, 2, 2, 2, 2, 2, 6 }, new int[] { 1, 5, 5, 5, 5, 5, 7 }, new String[] { "word", "SYNONYM", "SYNONYM", "SYNONYM", "SYNONYM", "SYNONYM", "word" }, new int[] { 1, 1, 0, 1, 1, 1, 1 }, new int[] { 1, 1, 2, 3, 1, 1, 1 });
    a.close();
}
Also used : CharsRefBuilder(org.apache.lucene.util.CharsRefBuilder) IntsRefBuilder(org.apache.lucene.util.IntsRefBuilder) Analyzer(org.apache.lucene.analysis.Analyzer) MockAnalyzer(org.apache.lucene.analysis.MockAnalyzer)

Aggregations

Analyzer (org.apache.lucene.analysis.Analyzer)1020 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)396 Tokenizer (org.apache.lucene.analysis.Tokenizer)265 MockTokenizer (org.apache.lucene.analysis.MockTokenizer)228 Document (org.apache.lucene.document.Document)207 Directory (org.apache.lucene.store.Directory)192 KeywordTokenizer (org.apache.lucene.analysis.core.KeywordTokenizer)176 BytesRef (org.apache.lucene.util.BytesRef)122 Test (org.junit.Test)119 TokenStream (org.apache.lucene.analysis.TokenStream)107 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)92 Term (org.apache.lucene.index.Term)92 IndexReader (org.apache.lucene.index.IndexReader)67 InputArrayIterator (org.apache.lucene.search.suggest.InputArrayIterator)65 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)64 Input (org.apache.lucene.search.suggest.Input)63 CharArraySet (org.apache.lucene.analysis.CharArraySet)58 ArrayList (java.util.ArrayList)57 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)57 TextField (org.apache.lucene.document.TextField)55