1
package org.apache.lucene.queryParser.standard.processors;
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.queryParser.core.QueryNodeException;
23
import org.apache.lucene.queryParser.core.config.FieldConfig;
24
import org.apache.lucene.queryParser.core.config.QueryConfigHandler;
25
import org.apache.lucene.queryParser.core.nodes.BoostQueryNode;
26
import org.apache.lucene.queryParser.core.nodes.FieldableNode;
27
import org.apache.lucene.queryParser.core.nodes.QueryNode;
28
import org.apache.lucene.queryParser.core.processors.QueryNodeProcessorImpl;
29
import org.apache.lucene.queryParser.core.util.StringUtils;
30
import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.ConfigurationKeys;
33
* This processor iterates the query node tree looking for every
34
* {@link FieldableNode} that has {@link ConfigurationKeys#BOOST} in its
35
* config. If there is, the boost is applied to that {@link FieldableNode}. <br/>
37
* @see ConfigurationKeys#BOOST
38
* @see QueryConfigHandler
41
public class BoostQueryNodeProcessor extends QueryNodeProcessorImpl {
44
protected QueryNode postProcessNode(QueryNode node) throws QueryNodeException {
46
if (node instanceof FieldableNode &&
47
(node.getParent() == null || !(node.getParent() instanceof FieldableNode))) {
49
FieldableNode fieldNode = (FieldableNode) node;
50
QueryConfigHandler config = getQueryConfigHandler();
53
CharSequence field = fieldNode.getField();
54
FieldConfig fieldConfig = config.getFieldConfig(StringUtils.toString(field));
56
if (fieldConfig != null) {
57
Float boost = fieldConfig.get(ConfigurationKeys.BOOST);
60
return new BoostQueryNode(node, boost);
74
protected QueryNode preProcessNode(QueryNode node) throws QueryNodeException {
81
protected List<QueryNode> setChildrenOrder(List<QueryNode> children)
82
throws QueryNodeException {