add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / contrib / xml-query-parser / src / java / org / apache / lucene / xmlparser / builders / DuplicateFilterBuilder.java
1 /*
2  * Created on 25-Jan-2006
3  */
4 package org.apache.lucene.xmlparser.builders;
5
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;
12
13 /**
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
20  *
21  *     http://www.apache.org/licenses/LICENSE-2.0
22  *
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.
28  */
29
30 /**
31  * 
32  */
33 public class DuplicateFilterBuilder implements FilterBuilder {
34         
35
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"))
41                 {
42                         df.setKeepMode(DuplicateFilter.KM_USE_FIRST_OCCURRENCE);
43                 }
44                 else
45                         if(keepMode.equalsIgnoreCase("last"))
46                         {
47                                 df.setKeepMode(DuplicateFilter.KM_USE_LAST_OCCURRENCE);
48                         }
49                         else
50                         {
51                                 throw new ParserException("Illegal keepMode attribute in DuplicateFilter:"+keepMode);
52                         }
53                 String processingMode=DOMUtils.getAttribute(e,"processingMode","full");
54                 if(processingMode.equalsIgnoreCase("full"))
55                 {
56                         df.setProcessingMode(DuplicateFilter.PM_FULL_VALIDATION);
57                 }
58                 else
59                         if(processingMode.equalsIgnoreCase("fast"))
60                         {
61                                 df.setProcessingMode(DuplicateFilter.PM_FAST_INVALIDATION);
62                         }
63                         else
64                         {
65                                 throw new ParserException("Illegal processingMode attribute in DuplicateFilter:"+processingMode);
66                         }
67                                         
68                 return df;
69         }
70
71 }