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