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.QueryConfigHandler;
24
import org.apache.lucene.queryParser.core.nodes.FuzzyQueryNode;
25
import org.apache.lucene.queryParser.core.nodes.QueryNode;
26
import org.apache.lucene.queryParser.core.processors.QueryNodeProcessorImpl;
27
import org.apache.lucene.queryParser.standard.config.FuzzyConfig;
28
import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.ConfigurationKeys;
29
import org.apache.lucene.search.FuzzyQuery;
32
* This processor iterates the query node tree looking for every
33
* {@link FuzzyQueryNode}, when this kind of node is found, it checks on the
34
* query configuration for
35
* {@link ConfigurationKeys#FUZZY_CONFIG}, gets the
36
* fuzzy prefix length and default similarity from it and set to the fuzzy node.
37
* For more information about fuzzy prefix length check: {@link FuzzyQuery}. <br/>
39
* @see ConfigurationKeys#FUZZY_CONFIG
43
public class FuzzyQueryNodeProcessor extends QueryNodeProcessorImpl {
46
protected QueryNode postProcessNode(QueryNode node) throws QueryNodeException {
53
protected QueryNode preProcessNode(QueryNode node) throws QueryNodeException {
55
if (node instanceof FuzzyQueryNode) {
56
FuzzyQueryNode fuzzyNode = (FuzzyQueryNode) node;
57
QueryConfigHandler config = getQueryConfigHandler();
59
FuzzyConfig fuzzyConfig = null;
61
if (config != null && (fuzzyConfig = config.get(ConfigurationKeys.FUZZY_CONFIG)) != null) {
62
fuzzyNode.setPrefixLength(fuzzyConfig.getPrefixLength());
64
if (fuzzyNode.getSimilarity() < 0) {
65
fuzzyNode.setSimilarity(fuzzyConfig.getMinSimilarity());
68
} else if (fuzzyNode.getSimilarity() < 0) {
69
throw new IllegalArgumentException("No FUZZY_CONFIG set in the config");
79
protected List<QueryNode> setChildrenOrder(List<QueryNode> children)
80
throws QueryNodeException {