1 package org.apache.lucene.facet.enhancements;
3 import java.io.IOException;
6 import org.apache.lucene.analysis.TokenStream;
8 import org.apache.lucene.facet.enhancements.params.EnhancementsIndexingParams;
9 import org.apache.lucene.facet.index.CategoryDocumentBuilder;
10 import org.apache.lucene.facet.index.attributes.CategoryProperty;
11 import org.apache.lucene.facet.index.streaming.CategoryAttributesStream;
12 import org.apache.lucene.facet.index.streaming.CategoryListTokenizer;
13 import org.apache.lucene.facet.index.streaming.CategoryParentsStream;
14 import org.apache.lucene.facet.index.streaming.CategoryTokenizer;
15 import org.apache.lucene.facet.taxonomy.TaxonomyWriter;
18 * Licensed to the Apache Software Foundation (ASF) under one or more
19 * contributor license agreements. See the NOTICE file distributed with
20 * this work for additional information regarding copyright ownership.
21 * The ASF licenses this file to You under the Apache License, Version 2.0
22 * (the "License"); you may not use this file except in compliance with
23 * the License. You may obtain a copy of the License at
25 * http://www.apache.org/licenses/LICENSE-2.0
27 * Unless required by applicable law or agreed to in writing, software
28 * distributed under the License is distributed on an "AS IS" BASIS,
29 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30 * See the License for the specific language governing permissions and
31 * limitations under the License.
35 * An {@link EnhancementsDocumentBuilder} is a {@link CategoryDocumentBuilder}
36 * which adds categories to documents according to the list of
37 * {@link CategoryEnhancement}s from {@link EnhancementsIndexingParams}. The
38 * additions over {@link CategoryDocumentBuilder} could be in both category
39 * tokens, and additional category lists.
41 * @lucene.experimental
43 public class EnhancementsDocumentBuilder extends CategoryDocumentBuilder {
46 * @param taxonomyWriter
48 * Indexing params which include {@link CategoryEnhancement}s.
51 public EnhancementsDocumentBuilder(TaxonomyWriter taxonomyWriter,
52 EnhancementsIndexingParams params) throws IOException {
53 super(taxonomyWriter, params);
57 protected TokenStream getParentsStream(CategoryAttributesStream categoryAttributesStream) {
58 List<Class<? extends CategoryProperty>> toRetainList = ((EnhancementsIndexingParams) indexingParams)
59 .getRetainableProperties();
60 if (toRetainList != null) {
61 CategoryParentsStream categoryParentsStream = new CategoryParentsStream(
62 categoryAttributesStream, taxonomyWriter, indexingParams);
63 for (Class<? extends CategoryProperty> toRetain : toRetainList) {
64 categoryParentsStream.addRetainableProperty(toRetain);
66 return categoryParentsStream;
68 return super.getParentsStream(categoryAttributesStream);
72 protected CategoryListTokenizer getCategoryListTokenizer(TokenStream categoryStream) {
73 CategoryListTokenizer tokenizer = super.getCategoryListTokenizer(categoryStream);
74 // Add tokenizer for each enhancement that produces category list
75 for (CategoryEnhancement enhancement : ((EnhancementsIndexingParams) indexingParams)
76 .getCategoryEnhancements()) {
77 if (enhancement.generatesCategoryList()) {
78 tokenizer = enhancement.getCategoryListTokenizer(tokenizer,
79 (EnhancementsIndexingParams) indexingParams,
87 protected CategoryTokenizer getCategoryTokenizer(TokenStream categoryStream)
89 return new EnhancementsCategoryTokenizer(categoryStream,
90 (EnhancementsIndexingParams) indexingParams);