1 package org.apache.lucene.queryParser.core.nodes;
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 import java.util.List;
22 import org.apache.lucene.messages.MessageImpl;
23 import org.apache.lucene.queryParser.core.QueryNodeError;
24 import org.apache.lucene.queryParser.core.QueryNodeException;
25 import org.apache.lucene.queryParser.core.messages.QueryParserMessages;
26 import org.apache.lucene.queryParser.core.parser.EscapeQuerySyntax;
29 * A {@link BoostQueryNode} boosts the QueryNode tree which is under this node.
30 * So, it must only and always have one child.
32 * The boost value may vary from 0.0 to 1.0.
35 public class BoostQueryNode extends QueryNodeImpl {
37 private static final long serialVersionUID = -3929082630855807593L;
39 private float value = 0;
42 * Constructs a boost node
45 * the query to be boosted
47 * the boost value, it may vary from 0.0 to 1.0
49 * @throws QueryNodeException
51 public BoostQueryNode(QueryNode query, float value) throws QueryNodeException {
53 throw new QueryNodeError(new MessageImpl(
54 QueryParserMessages.NODE_ACTION_NOT_SUPPORTED, "query", "null"));
64 * Returns the single child which this node boosts.
66 * @return the single child which this node boosts
68 public QueryNode getChild() {
69 List<QueryNode> children = getChildren();
71 if (children == null || children.size() == 0) {
75 return children.get(0);
80 * Returns the boost value. It may vary from 0.0 to 1.0.
82 * @return the boost value
84 public float getValue() {
89 * Returns the boost value parsed to a string.
91 * @return the parsed value
93 private CharSequence getValueString() {
94 Float f = Float.valueOf(this.value);
95 if (f == f.longValue())
96 return "" + f.longValue();
103 public String toString() {
104 return "<boost value='" + getValueString() + "'>" + "\n"
105 + getChild().toString() + "\n</boost>";
108 public CharSequence toQueryString(EscapeQuerySyntax escapeSyntaxParser) {
109 if (getChild() == null)
111 return getChild().toQueryString(escapeSyntaxParser) + "^"
116 public QueryNode cloneTree() throws CloneNotSupportedException {
117 BoostQueryNode clone = (BoostQueryNode) super.cloneTree();
119 clone.value = this.value;