pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / contrib / xml-query-parser / src / java / org / apache / lucene / xmlparser / builders / FilteredQueryBuilder.java
1 /*
2  * Created on 25-Jan-2006
3  */
4 package org.apache.lucene.xmlparser.builders;
5
6 import org.apache.lucene.search.Filter;
7 import org.apache.lucene.search.FilteredQuery;
8 import org.apache.lucene.search.Query;
9 import org.apache.lucene.xmlparser.DOMUtils;
10 import org.apache.lucene.xmlparser.FilterBuilder;
11 import org.apache.lucene.xmlparser.ParserException;
12 import org.apache.lucene.xmlparser.QueryBuilder;
13 import org.w3c.dom.Element;
14
15 /**
16  * Licensed to the Apache Software Foundation (ASF) under one or more
17  * contributor license agreements.  See the NOTICE file distributed with
18  * this work for additional information regarding copyright ownership.
19  * The ASF licenses this file to You under the Apache License, Version 2.0
20  * (the "License"); you may not use this file except in compliance with
21  * the License.  You may obtain a copy of the License at
22  *
23  *     http://www.apache.org/licenses/LICENSE-2.0
24  *
25  * Unless required by applicable law or agreed to in writing, software
26  * distributed under the License is distributed on an "AS IS" BASIS,
27  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28  * See the License for the specific language governing permissions and
29  * limitations under the License.
30  */
31
32 /**
33  * 
34  */
35 public class FilteredQueryBuilder implements QueryBuilder {
36         
37         private FilterBuilder filterFactory;
38         private QueryBuilder queryFactory;
39
40         public FilteredQueryBuilder(FilterBuilder filterFactory, QueryBuilder queryFactory)
41         {
42                 this.filterFactory=filterFactory;
43                 this.queryFactory=queryFactory;
44                 
45         }
46
47         /* (non-Javadoc)
48          * @see org.apache.lucene.xmlparser.QueryObjectBuilder#process(org.w3c.dom.Element)
49          */
50         public Query getQuery(Element e) throws ParserException {       
51             Element filterElement=DOMUtils.getChildByTagOrFail(e,"Filter");
52             filterElement=DOMUtils.getFirstChildOrFail(filterElement);
53             Filter f=filterFactory.getFilter(filterElement);
54  
55             Element queryElement=DOMUtils.getChildByTagOrFail(e,"Query");
56             queryElement=DOMUtils.getFirstChildOrFail(queryElement);
57             Query q=queryFactory.getQuery(queryElement);
58             
59             FilteredQuery fq = new FilteredQuery(q,f);
60             fq.setBoost(DOMUtils.getAttribute(e,"boost",1.0f));
61             return fq;          
62         }
63
64 }