1 package org.apache.lucene.queryParser.standard.config;
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.
22 import org.apache.lucene.queryParser.core.config.FieldConfig;
23 import org.apache.lucene.queryParser.core.config.FieldConfigListener;
24 import org.apache.lucene.queryParser.core.config.QueryConfigHandler;
25 import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.ConfigurationKeys;
28 * This listener is used to listen to {@link FieldConfig} requests in
29 * {@link QueryConfigHandler} and add {@link ConfigurationKeys#NUMERIC_CONFIG}
30 * based on the {@link ConfigurationKeys#NUMERIC_CONFIG_MAP} set in the
31 * {@link QueryConfigHandler}.
34 * @see QueryConfigHandler
35 * @see ConfigurationKeys#NUMERIC_CONFIG
36 * @see ConfigurationKeys#NUMERIC_CONFIG_MAP
38 public class NumericFieldConfigListener implements FieldConfigListener {
40 final private QueryConfigHandler config;
43 * Construcs a {@link NumericFieldConfigListener} object using the given {@link QueryConfigHandler}.
45 * @param config the {@link QueryConfigHandler} it will listen too
47 public NumericFieldConfigListener(QueryConfigHandler config) {
50 throw new IllegalArgumentException("config cannot be null!");
57 public void buildFieldConfig(FieldConfig fieldConfig) {
58 Map<String,NumericConfig> numericConfigMap = config
59 .get(ConfigurationKeys.NUMERIC_CONFIG_MAP);
61 if (numericConfigMap != null) {
62 NumericConfig numericConfig = numericConfigMap
63 .get(fieldConfig.getField());
65 if (numericConfig != null) {
66 fieldConfig.set(ConfigurationKeys.NUMERIC_CONFIG, numericConfig);