1 package org.apache.lucene.analysis.miscellaneous;
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 import org.apache.lucene.analysis.Token;
21 import org.apache.lucene.analysis.TokenStream;
23 import java.io.IOException;
26 * Links two {@link PrefixAwareTokenFilter}.
28 * <b>NOTE:</b> This filter might not behave correctly if used with custom Attributes, i.e. Attributes other than
29 * the ones located in org.apache.lucene.analysis.tokenattributes.
31 public class PrefixAndSuffixAwareTokenFilter extends TokenStream {
33 private PrefixAwareTokenFilter suffix;
35 public PrefixAndSuffixAwareTokenFilter(TokenStream prefix, TokenStream input, TokenStream suffix) {
37 prefix = new PrefixAwareTokenFilter(prefix, input) {
39 public Token updateSuffixToken(Token suffixToken, Token lastInputToken) {
40 return PrefixAndSuffixAwareTokenFilter.this.updateInputToken(suffixToken, lastInputToken);
43 this.suffix = new PrefixAwareTokenFilter(prefix, suffix) {
45 public Token updateSuffixToken(Token suffixToken, Token lastInputToken) {
46 return PrefixAndSuffixAwareTokenFilter.this.updateSuffixToken(suffixToken, lastInputToken);
51 public Token updateInputToken(Token inputToken, Token lastPrefixToken) {
52 inputToken.setStartOffset(lastPrefixToken.endOffset() + inputToken.startOffset());
53 inputToken.setEndOffset(lastPrefixToken.endOffset() + inputToken.endOffset());
57 public Token updateSuffixToken(Token suffixToken, Token lastInputToken) {
58 suffixToken.setStartOffset(lastInputToken.endOffset() + suffixToken.startOffset());
59 suffixToken.setEndOffset(lastInputToken.endOffset() + suffixToken.endOffset());
65 public final boolean incrementToken() throws IOException {
66 return suffix.incrementToken();
70 public void reset() throws IOException {
76 public void close() throws IOException {
81 public void end() throws IOException {