2 * Created on 25-Jan-2006
4 package org.apache.lucene.xmlparser.builders;
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;
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.
37 public class BooleanFilterBuilder implements FilterBuilder {
39 private FilterBuilder factory;
41 public BooleanFilterBuilder(FilterBuilder factory)
46 public Filter getFilter(Element e) throws ParserException {
47 BooleanFilter bf=new BooleanFilter();
48 NodeList nl = e.getChildNodes();
50 for(int i=0;i<nl.getLength();i++)
52 Node node = nl.item(i);
53 if(node.getNodeName().equals("Clause"))
55 Element clauseElem=(Element) node;
56 BooleanClause.Occur occurs=BooleanQueryBuilder.getOccursValue(clauseElem);
58 Element clauseFilter=DOMUtils.getFirstChildOrFail(clauseElem);
59 Filter f=factory.getFilter(clauseFilter);
60 bf.add(new FilterClause(f,occurs));