01: /*
02: * Created on 25-Jan-2006
03: */
04: package org.apache.lucene.xmlparser.builders;
05:
06: import org.apache.lucene.search.Filter;
07: import org.apache.lucene.search.FilteredQuery;
08: import org.apache.lucene.search.Query;
09: 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: * @author maharwood
33: */
34: public class FilteredQueryBuilder implements QueryBuilder {
35:
36: private FilterBuilder filterFactory;
37: private QueryBuilder queryFactory;
38:
39: public FilteredQueryBuilder(FilterBuilder filterFactory,
40: QueryBuilder queryFactory) {
41: this .filterFactory = filterFactory;
42: this .queryFactory = queryFactory;
43:
44: }
45:
46: /* (non-Javadoc)
47: * @see org.apache.lucene.xmlparser.QueryObjectBuilder#process(org.w3c.dom.Element)
48: */
49: public Query getQuery(Element e) throws ParserException {
50: Element filterElement = DOMUtils.getChildByTagOrFail(e,
51: "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: }
|