2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
20 using OffsetAttribute = Mono.Lucene.Net.Analysis.Tokenattributes.OffsetAttribute;
21 using TermAttribute = Mono.Lucene.Net.Analysis.Tokenattributes.TermAttribute;
22 using AttributeSource = Mono.Lucene.Net.Util.AttributeSource;
24 namespace Mono.Lucene.Net.Analysis
27 /// <summary> Emits the entire input as a single token.</summary>
28 public class KeywordTokenizer:Tokenizer
31 private const int DEFAULT_BUFFER_SIZE = 256;
34 private int finalOffset;
35 private TermAttribute termAtt;
36 private OffsetAttribute offsetAtt;
38 public KeywordTokenizer(System.IO.TextReader input):this(input, DEFAULT_BUFFER_SIZE)
42 public KeywordTokenizer(System.IO.TextReader input, int bufferSize):base(input)
47 public KeywordTokenizer(AttributeSource source, System.IO.TextReader input, int bufferSize):base(source, input)
52 public KeywordTokenizer(AttributeFactory factory, System.IO.TextReader input, int bufferSize):base(factory, input)
57 private void Init(int bufferSize)
60 termAtt = (TermAttribute) AddAttribute(typeof(TermAttribute));
61 offsetAtt = (OffsetAttribute) AddAttribute(typeof(OffsetAttribute));
62 termAtt.ResizeTermBuffer(bufferSize);
65 public override bool IncrementToken()
72 char[] buffer = termAtt.TermBuffer();
75 int length = input.Read(buffer, upto, buffer.Length - upto);
79 if (upto == buffer.Length)
80 buffer = termAtt.ResizeTermBuffer(1 + buffer.Length);
82 termAtt.SetTermLength(upto);
83 finalOffset = CorrectOffset(upto);
84 offsetAtt.SetOffset(CorrectOffset(0), finalOffset);
90 public override void End()
93 offsetAtt.SetOffset(finalOffset, finalOffset);
96 /// <deprecated> Will be removed in Lucene 3.0. This method is final, as it should
97 /// not be overridden. Delegates to the backwards compatibility layer.
99 [Obsolete("Will be removed in Lucene 3.0. This method is final, as it should not be overridden. Delegates to the backwards compatibility layer. ")]
100 public override Token Next(Token reusableToken)
102 return base.Next(reusableToken);
105 /// <deprecated> Will be removed in Lucene 3.0. This method is final, as it should
106 /// not be overridden. Delegates to the backwards compatibility layer.
108 [Obsolete("Will be removed in Lucene 3.0. This method is final, as it should not be overridden. Delegates to the backwards compatibility layer. ")]
109 public override Token Next()
114 public override void Reset(System.IO.TextReader input)