1 package org.apache.lucene.facet.enhancements.association;
3 import java.io.IOException;
5 import org.apache.lucene.analysis.TokenStream;
7 import org.apache.lucene.facet.enhancements.CategoryEnhancement;
8 import org.apache.lucene.facet.enhancements.params.EnhancementsIndexingParams;
9 import org.apache.lucene.facet.index.CategoryListPayloadStream;
10 import org.apache.lucene.facet.index.attributes.OrdinalProperty;
11 import org.apache.lucene.facet.index.streaming.CategoryListTokenizer;
12 import org.apache.lucene.util.encoding.SimpleIntEncoder;
15 * Licensed to the Apache Software Foundation (ASF) under one or more
16 * contributor license agreements. See the NOTICE file distributed with
17 * this work for additional information regarding copyright ownership.
18 * The ASF licenses this file to You under the Apache License, Version 2.0
19 * (the "License"); you may not use this file except in compliance with
20 * the License. You may obtain a copy of the License at
22 * http://www.apache.org/licenses/LICENSE-2.0
24 * Unless required by applicable law or agreed to in writing, software
25 * distributed under the License is distributed on an "AS IS" BASIS,
26 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27 * See the License for the specific language governing permissions and
28 * limitations under the License.
32 * Tokenizer for associations of a category
34 * @lucene.experimental
36 public class AssociationListTokenizer extends CategoryListTokenizer {
38 protected CategoryListPayloadStream payloadStream;
40 private String categoryListTermText;
42 public AssociationListTokenizer(TokenStream input,
43 EnhancementsIndexingParams indexingParams, CategoryEnhancement enhancement) {
44 super(input, indexingParams);
45 categoryListTermText = enhancement.getCategoryListTermText();
49 protected void handleStartOfInput() throws IOException {
54 public final boolean incrementToken() throws IOException {
55 if (input.incrementToken()) {
56 if (categoryAttribute != null) {
57 AssociationProperty associationProperty = AssociationEnhancement
58 .getAssociationProperty(categoryAttribute);
59 if (associationProperty != null
60 && associationProperty.hasBeenSet()) {
61 OrdinalProperty ordinalProperty = (OrdinalProperty) categoryAttribute
62 .getProperty(OrdinalProperty.class);
63 if (ordinalProperty == null) {
64 throw new IOException(
65 "Error: Association without ordinal");
68 if (payloadStream == null) {
69 payloadStream = new CategoryListPayloadStream(
70 new SimpleIntEncoder());
72 payloadStream.appendIntToStream(ordinalProperty
74 payloadStream.appendIntToStream(associationProperty
80 if (payloadStream != null) {
81 termAttribute.setEmpty().append(categoryListTermText);
82 payload.setData(payloadStream.convertStreamToByteArray());
83 payloadAttribute.setPayload(payload);