@@ -0,0 +1,3043 @@
+/*%0A * Licensed to the Apache Software Foundation (ASF) under one or more%0A * contributor license agreements.  See the NOTICE file distributed with%0A * this work for additional information regarding copyright ownership.%0A * The ASF licenses this file to You under the Apache License, Version 2.0%0A * (the %22License%22); you may not use this file except in compliance with%0A * the License.  You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required byOCP applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage com.shaie;%0A%0Aimport java.io.StringReader;%0A%0Aimport org.apache.lucene.analysis.TokenStream;%0Aimport org.apache.lucene.analysis.Tokenizer;%0Aimport org.apache.lucene.analysis.core.WhitespaceTokenizer;%0Aimport org.apache.lucene.analysis.synonym.SynonymFilter;%0Aimport org.apache.lucene.analysis.synonym.SynonymMap;%0Aimport org.apache.lucene.analysis.tokenattributes.CharTermAttribute;%0Aimport org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute;%0Aimport org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute;%0Aimport org.apache.lucene.util.CharsRef;%0Aimport org.apache.lucene.util.CharsRefBuilder;%0A%0Apublic class SynonymFilterExample %7B%0A%0A    @SuppressWarnings(%22resource%22)%0A    public static void main(String%5B%5D args) throws Exception %7B%0A        final Tokenizer tok = new WhitespaceTokenizer();%0A        tok.setReader(new StringReader(%22dark sea green sea green%22));%0A%0A        final SynonymMap.Builder builder = new SynonymMap.Builder(true);%0A        addSynonym(%22dark sea green%22, %22color%22, builder);%0A        addSynonym(%22green%22, %22color%22, builder);%0A        addSynonym(%22dark sea%22, %22color%22, builder);%0A        addSynonym(%22sea green%22, %22color%22, builder);%0A        final SynonymMap synMap = builder.build();%0A        final TokenStream ts = new SynonymFilter(tok, synMap, true);%0A%0A        final CharTermAttribute termAtt = ts.addAttribute(CharTermAttribute.class);%0A        final PositionIncrementAttribute posIncrAtt = ts.addAttribute(PositionIncrementAttribute.class);%0A        final PositionLengthAttribute posLengthAtt = ts.addAttribute(PositionLengthAttribute.class);%0A%0A        ts.reset();%0A        int pos = -1;%0A        while (ts.incrementToken()) %7B%0A            pos += posIncrAtt.getPositionIncrement();%0A            System.out.println(%22term=%22 + termAtt + %22, pos=%22 + pos + %22, posLen=%22 + posLengthAtt.getPositionLength());%0A        %7D%0A        ts.end();%0A        ts.close();%0A    %7D%0A%0A    private static void addSynonym(String input, String output, SynonymMap.Builder builder) %7B%0A        final CharsRef inputWords = SynonymMap.Builder.join(input.split(%22 %22), new CharsRefBuilder());%0A        final CharsRef outputWords = SynonymMap.Builder.join(output.split(%22 %22), new CharsRefBuilder());%0A        builder.add(inputWords, outputWords, true);%0A    %7D%0A%0A%7D

Add SynonymFilterExample