2 * Created on 25-Jan-2006
4 package org.apache.lucene.xmlparser.builders;
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;
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
23 * http://www.apache.org/licenses/LICENSE-2.0
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.
35 public class FilteredQueryBuilder implements QueryBuilder {
37 private FilterBuilder filterFactory;
38 private QueryBuilder queryFactory;
40 public FilteredQueryBuilder(FilterBuilder filterFactory, QueryBuilder queryFactory)
42 this.filterFactory=filterFactory;
43 this.queryFactory=queryFactory;
48 * @see org.apache.lucene.xmlparser.QueryObjectBuilder#process(org.w3c.dom.Element)
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);
55 Element queryElement=DOMUtils.getChildByTagOrFail(e,"Query");
56 queryElement=DOMUtils.getFirstChildOrFail(queryElement);
57 Query q=queryFactory.getQuery(queryElement);
59 FilteredQuery fq = new FilteredQuery(q,f);
60 fq.setBoost(DOMUtils.getAttribute(e,"boost",1.0f));