/*
 * Licensed to Elasticsearch under one or more contributor
 * license agreements. See the NOTICE file distributed with
 * this work for additional information regarding copyright
 * ownership. Elasticsearch 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.mapper;

import java.util.List;

import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermInSetQuery;
import org.apache.lucene.search.TermRangeQuery;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.index.query.QueryShardContext;

/** Base class for {@link MappedFieldType} implementations that use the same
 * representation for internal index terms as the external representation so
 * that partial matching queries such as prefix, wildcard and fuzzy queries
 * can be implemented. */
public abstract class StringFieldType extends TermBasedFieldType {

    public StringFieldType(String name, boolean isSearchable, boolean hasDocValues) {
        super(name, isSearchable, hasDocValues);
    }

    protected StringFieldType(MappedFieldType ref) {
        super(ref);
    }

    @Override
    public Query termsQuery(List<?> values, QueryShardContext context) {
        failIfNotIndexed();
        BytesRef[] bytesRefs = new BytesRef[values.size()];
        for (int i = 0; i < bytesRefs.length; i++) {
            bytesRefs[i] = indexedValueForSearch(values.get(i));
        }
        return new TermInSetQuery(name(), bytesRefs);
    }

    @Override
    public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper, QueryShardContext context) {
        failIfNotIndexed();
        return new TermRangeQuery(name(),
            lowerTerm == null ? null : indexedValueForSearch(lowerTerm),
            upperTerm == null ? null : indexedValueForSearch(upperTerm),
            includeLower, includeUpper);
    }
}

@@ -828,32 +828,8 @@
 r;%0A%0A
-import java.util.List;%0A%0A
 impo
@@ -903,106 +903,18 @@
 Term
-InSetQuery;%0Aimport org.apache.lucene.search.TermRangeQuery;%0Aimport org.apache.lucene.util.BytesRef
+RangeQuery
 ;%0Aim
@@ -1518,372 +1518,8 @@
  %7D%0A%0A
-    @Override%0A    public Query termsQuery(List%3C?%3E values, QueryShardContext context) %7B%0A        failIfNotIndexed();%0A        BytesRef%5B%5D bytesRefs = new BytesRef%5Bvalues.size()%5D;%0A        for (int i = 0; i %3C bytesRefs.length; i++) %7B%0A            bytesRefs%5Bi%5D = indexedValueForSearch(values.get(i));%0A        %7D%0A        return new TermInSetQuery(name(), bytesRefs);%0A    %7D%0A%0A
     

Remove termsQuery override in StringFieldType