add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / contrib / facet / src / java / org / apache / lucene / facet / index / streaming / CategoryTokenizer.java
1 package org.apache.lucene.facet.index.streaming;
2
3 import java.io.IOException;
4
5 import org.apache.lucene.analysis.TokenStream;
6 import org.apache.lucene.analysis.tokenattributes.PayloadAttribute;
7 import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
8
9 import org.apache.lucene.facet.index.params.FacetIndexingParams;
10 import org.apache.lucene.facet.taxonomy.CategoryPath;
11
12 /**
13  * Licensed to the Apache Software Foundation (ASF) under one or more
14  * contributor license agreements.  See the NOTICE file distributed with
15  * this work for additional information regarding copyright ownership.
16  * The ASF licenses this file to You under the Apache License, Version 2.0
17  * (the "License"); you may not use this file except in compliance with
18  * the License.  You may obtain a copy of the License at
19  *
20  *     http://www.apache.org/licenses/LICENSE-2.0
21  *
22  * Unless required by applicable law or agreed to in writing, software
23  * distributed under the License is distributed on an "AS IS" BASIS,
24  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25  * See the License for the specific language governing permissions and
26  * limitations under the License.
27  */
28
29 /**
30  * Basic class for setting the {@link CharTermAttribute}s and
31  * {@link PayloadAttribute}s of category tokens.
32  * 
33  * @lucene.experimental
34  */
35 public class CategoryTokenizer extends CategoryTokenizerBase {
36
37   /**
38    * @see CategoryTokenizerBase#CategoryTokenizerBase(TokenStream,
39    *      FacetIndexingParams)
40    */
41   public CategoryTokenizer(TokenStream input,
42       FacetIndexingParams indexingParams) {
43     super(input, indexingParams);
44   }
45
46   @Override
47   public final boolean incrementToken() throws IOException {
48     if (input.incrementToken()) {
49       if (categoryAttribute != null && categoryAttribute.getCategoryPath() != null) {
50         CategoryPath categoryPath = categoryAttribute.getCategoryPath();
51         char[] termBuffer = termAttribute.resizeBuffer(categoryPath.charsNeededForFullPath());
52         int nChars = indexingParams.drillDownTermText(categoryPath, termBuffer);
53         termAttribute.setLength(nChars);
54         setPayload();
55       }
56       return true;
57     }
58     return false;
59   }
60
61   /**
62    * Set the payload of the current category token.
63    */
64   protected void setPayload() {
65   }
66
67 }