/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.elasticsearch.index.query;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.queryparser.XSimpleQueryParser;
import org.apache.lucene.search.Query;
import org.elasticsearch.ElasticsearchIllegalStateException;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.MapperService;

import java.io.IOException;
import java.util.Collections;
import java.util.Locale;
import java.util.Map;

import static org.elasticsearch.index.query.support.QueryParsers.wrapSmartNameQuery;

/**
 * Wrapper class for Lucene's SimpleQueryParser that allows us to redefine
 * different types of queries.
 */
public class SimpleQueryParser extends XSimpleQueryParser {

    private final boolean lowercaseExpandedTerms;

    /** Creates a new parser with custom flags used to enable/disable certain features. */
    public SimpleQueryParser(Analyzer analyzer, Map<String, Float> weights, int flags, boolean lowercaseExpandedTerms) {
        super(analyzer, weights, flags);
        this.lowercaseExpandedTerms = lowercaseExpandedTerms;
    }

    /**
     * Dispatches to Lucene's SimpleQueryParser's newFuzzyQuery, optionally
     * lowercasing the term first
     */
    @Override
    public Query newFuzzyQuery(String text, int fuzziness) {
        if (lowercaseExpandedTerms) {
            text = text.toLowerCase(Locale.ROOT);
        }
        return super.newFuzzyQuery(text, fuzziness);
    }

    /**
     * Dispatches to Lucene's SimpleQueryParser's newPrefixQuery, optionally
     * lowercasing the term first
     */
    @Override
    public Query newPrefixQuery(String text) {
        if (lowercaseExpandedTerms) {
            text = text.toLowerCase(Locale.ROOT);
        }
        return super.newPrefixQuery(text);
    }
}

@@ -15,44 +15,21 @@
  to 
-the Apache Software Foundation (ASF)
+Elasticsearch
  und
@@ -42,19 +42,16 @@
  or more
-%0A *
  contrib
@@ -54,16 +54,19 @@
 tributor
+%0A *
  license
@@ -77,17 +77,16 @@
 eements.
- 
  See the
@@ -174,16 +174,19 @@
 opyright
+%0A *
  ownersh
@@ -192,19 +192,22 @@
 hip.
-%0A * The ASF
+ Elasticsearch
  lic
@@ -229,17 +229,17 @@
  to 
-Y
+y
 ou under
  the
@@ -230,24 +230,27 @@
 to you under
+%0A *
  the Apache 
@@ -269,19 +269,16 @@
 sion 2.0
-%0A *
  (the %22L
@@ -294,16 +294,19 @@
  you may
+%0A *
  not use
@@ -341,19 +341,16 @@
 nce with
-%0A *
  the Lic
@@ -354,17 +354,19 @@
 License.
- 
+%0A *
  You may
@@ -407,17 +407,16 @@
 *%0A *    
- 
 http://w
@@ -514,16 +514,19 @@
 writing,
+%0A *
  softwar
@@ -526,19 +526,16 @@
 software
-%0A *
  distrib
@@ -577,16 +577,19 @@
 ed on an
+%0A *
  %22AS IS%22
@@ -595,19 +595,16 @@
 %22 BASIS,
-%0A *
  WITHOUT
@@ -635,16 +635,19 @@
 S OF ANY
+%0A *
  KIND, e
@@ -671,19 +671,17 @@
 implied.
-%0A *
+ 
  See the
@@ -696,16 +696,19 @@
  for the
+%0A *
  specifi
@@ -743,19 +743,16 @@
 ions and
-%0A *
  limitat
@@ -755,16 +755,19 @@
 itations
+%0A *
  under t
@@ -782,17 +782,16 @@
 se.%0A */%0A
-%0A
 package 

Fix license header for SimpleQueryParser