2 * Created on 25-Jan-2006
4 package org.apache.lucene.xmlparser.builders;
6 import org.apache.lucene.search.DuplicateFilter;
7 import org.apache.lucene.search.Filter;
8 import org.apache.lucene.xmlparser.DOMUtils;
9 import org.apache.lucene.xmlparser.FilterBuilder;
10 import org.apache.lucene.xmlparser.ParserException;
11 import org.w3c.dom.Element;
14 * Licensed to the Apache Software Foundation (ASF) under one or more
15 * contributor license agreements. See the NOTICE file distributed with
16 * this work for additional information regarding copyright ownership.
17 * The ASF licenses this file to You under the Apache License, Version 2.0
18 * (the "License"); you may not use this file except in compliance with
19 * the License. You may obtain a copy of the License at
21 * http://www.apache.org/licenses/LICENSE-2.0
23 * Unless required by applicable law or agreed to in writing, software
24 * distributed under the License is distributed on an "AS IS" BASIS,
25 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26 * See the License for the specific language governing permissions and
27 * limitations under the License.
33 public class DuplicateFilterBuilder implements FilterBuilder {
36 public Filter getFilter(Element e) throws ParserException {
37 String fieldName=DOMUtils.getAttributeWithInheritanceOrFail(e,"fieldName");
38 DuplicateFilter df=new DuplicateFilter(fieldName);
39 String keepMode=DOMUtils.getAttribute(e,"keepMode","first");
40 if(keepMode.equalsIgnoreCase("first"))
42 df.setKeepMode(DuplicateFilter.KM_USE_FIRST_OCCURRENCE);
45 if(keepMode.equalsIgnoreCase("last"))
47 df.setKeepMode(DuplicateFilter.KM_USE_LAST_OCCURRENCE);
51 throw new ParserException("Illegal keepMode attribute in DuplicateFilter:"+keepMode);
53 String processingMode=DOMUtils.getAttribute(e,"processingMode","full");
54 if(processingMode.equalsIgnoreCase("full"))
56 df.setProcessingMode(DuplicateFilter.PM_FULL_VALIDATION);
59 if(processingMode.equalsIgnoreCase("fast"))
61 df.setProcessingMode(DuplicateFilter.PM_FAST_INVALIDATION);
65 throw new ParserException("Illegal processingMode attribute in DuplicateFilter:"+processingMode);