pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / contrib / xml-query-parser / src / java / org / apache / lucene / xmlparser / builders / BooleanFilterBuilder.java
1 /*
2  * Created on 25-Jan-2006
3  */
4 package org.apache.lucene.xmlparser.builders;
5
6 import org.apache.lucene.search.BooleanClause;
7 import org.apache.lucene.search.BooleanFilter;
8 import org.apache.lucene.search.Filter;
9 import org.apache.lucene.search.FilterClause;
10 import org.apache.lucene.xmlparser.DOMUtils;
11 import org.apache.lucene.xmlparser.FilterBuilder;
12 import org.apache.lucene.xmlparser.ParserException;
13 import org.w3c.dom.Element;
14 import org.w3c.dom.Node;
15 import org.w3c.dom.NodeList;
16
17 /**
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
24  *
25  *     http://www.apache.org/licenses/LICENSE-2.0
26  *
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.
32  */
33
34 /**
35  * 
36  */
37 public class BooleanFilterBuilder implements FilterBuilder {
38         
39         private FilterBuilder factory;
40
41         public BooleanFilterBuilder(FilterBuilder factory)
42         {
43                 this.factory=factory;
44         }
45
46         public Filter getFilter(Element e) throws ParserException {
47                 BooleanFilter bf=new BooleanFilter();
48                 NodeList nl = e.getChildNodes();
49                 
50                 for(int i=0;i<nl.getLength();i++)
51                 {
52                         Node node = nl.item(i);
53                         if(node.getNodeName().equals("Clause"))
54                         {
55                                 Element clauseElem=(Element) node;
56                                 BooleanClause.Occur occurs=BooleanQueryBuilder.getOccursValue(clauseElem);
57                         
58                                 Element clauseFilter=DOMUtils.getFirstChildOrFail(clauseElem);
59                                 Filter f=factory.getFilter(clauseFilter);
60                                 bf.add(new FilterClause(f,occurs));
61                         }
62                 }
63                 
64                 return bf;
65         }
66
67 }