[Remove] TypeFieldMapper (#3196)

Removes last trace of TypeFieldMapper since types have been removed and
NestedPathFieldMapper is now available.

Signed-off-by: Nicholas Walter Knize <nknize@apache.org>
This commit is contained in:
Nick Knize 2022-05-05 09:35:41 -05:00 committed by GitHub
parent 112a108246
commit 741445a574
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 1 additions and 192 deletions

View File

@ -33,7 +33,6 @@
package org.opensearch.common.lucene.search;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.Term;
import org.apache.lucene.queries.ExtendedCommonTermsQuery;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanClause.Occur;
@ -43,17 +42,14 @@ import org.apache.lucene.search.Explanation;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.MatchNoDocsQuery;
import org.apache.lucene.search.PrefixQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.QueryVisitor;
import org.apache.lucene.search.ScoreMode;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.Weight;
import org.apache.lucene.util.BytesRef;
import org.opensearch.OpenSearchException;
import org.opensearch.common.Nullable;
import org.opensearch.index.mapper.SeqNoFieldMapper;
import org.opensearch.index.mapper.TypeFieldMapper;
import java.io.IOException;
import java.util.Collection;
@ -87,7 +83,7 @@ public class Queries {
}
public static Query newNestedFilter() {
return new PrefixQuery(new Term(TypeFieldMapper.NAME, new BytesRef("__")));
return not(newNonNestedFilter());
}
/**

View File

@ -1,187 +0,0 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
/*
* 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.
*/
/*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/
package org.opensearch.index.mapper;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.FieldType;
import org.apache.lucene.document.SortedSetDocValuesField;
import org.apache.lucene.index.IndexOptions;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.MatchNoDocsQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.util.BytesRef;
import org.opensearch.common.geo.ShapeRelation;
import org.opensearch.common.regex.Regex;
import org.opensearch.common.time.DateMathParser;
import org.opensearch.index.fielddata.IndexFieldData;
import org.opensearch.index.fielddata.plain.ConstantIndexFieldData;
import org.opensearch.index.query.QueryShardContext;
import org.opensearch.search.aggregations.support.CoreValuesSourceType;
import org.opensearch.search.lookup.SearchLookup;
import java.time.ZoneId;
import java.util.Collections;
import java.util.Objects;
import java.util.function.Supplier;
// Todo: Remove TypeFieldMapper once we have NestedFieldMapper implementation
public class TypeFieldMapper extends MetadataFieldMapper {
public static final String NAME = "_type";
public static final String CONTENT_TYPE = "_type";
public static final TypeParser PARSER = new FixedTypeParser(c -> new TypeFieldMapper());
public static class Defaults {
public static final FieldType NESTED_FIELD_TYPE = new FieldType();
static {
NESTED_FIELD_TYPE.setIndexOptions(IndexOptions.DOCS);
NESTED_FIELD_TYPE.setTokenized(false);
NESTED_FIELD_TYPE.setStored(false);
NESTED_FIELD_TYPE.setOmitNorms(true);
NESTED_FIELD_TYPE.freeze();
}
}
public static final class TypeFieldType extends ConstantFieldType {
private final String type;
public TypeFieldType(String type) {
super(NAME, Collections.emptyMap());
this.type = type;
}
@Override
public String typeName() {
return CONTENT_TYPE;
}
@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName, Supplier<SearchLookup> searchLookup) {
return new ConstantIndexFieldData.Builder(type, name(), CoreValuesSourceType.BYTES);
}
@Override
public ValueFetcher valueFetcher(QueryShardContext context, SearchLookup lookup, String format) {
throw new UnsupportedOperationException("Cannot fetch values for internal field [" + name() + "].");
}
@Override
public Query existsQuery(QueryShardContext context) {
return new MatchAllDocsQuery();
}
@Override
protected boolean matches(String pattern, boolean caseInsensitive, QueryShardContext context) {
if (type == null) {
return false;
}
return Regex.simpleMatch(pattern, type, caseInsensitive);
}
@Override
public Query rangeQuery(
Object lowerTerm,
Object upperTerm,
boolean includeLower,
boolean includeUpper,
ShapeRelation relation,
ZoneId timeZone,
DateMathParser parser,
QueryShardContext context
) {
BytesRef lower = (BytesRef) lowerTerm;
BytesRef upper = (BytesRef) upperTerm;
if (includeLower) {
if (lower.utf8ToString().compareTo(type) > 0) {
return new MatchNoDocsQuery();
}
} else {
if (lower.utf8ToString().compareTo(type) >= 0) {
return new MatchNoDocsQuery();
}
}
if (includeUpper) {
if (upper.utf8ToString().compareTo(type) < 0) {
return new MatchNoDocsQuery();
}
} else {
if (upper.utf8ToString().compareTo(type) <= 0) {
return new MatchNoDocsQuery();
}
}
return new MatchAllDocsQuery();
}
/**
* Build a type filter
*
* This does not emit a deprecation warning, as it is only called when a type
* has been specified in a REST request and warnings will have already been
* emitted at the REST layer.
*/
public Query typeFilter(String[] types) {
for (String t : types) {
if (Objects.equals(this.type, t)) {
return new MatchAllDocsQuery();
}
}
return new MatchNoDocsQuery();
}
}
private TypeFieldMapper() {
super(new TypeFieldType(null));
}
@Override
public void preParse(ParseContext context) {
if (fieldType.indexOptions() == IndexOptions.NONE && !fieldType.stored()) {
return;
}
context.doc().add(new Field(fieldType().name(), MapperService.SINGLE_MAPPING_NAME, fieldType));
if (fieldType().hasDocValues()) {
context.doc().add(new SortedSetDocValuesField(fieldType().name(), new BytesRef(MapperService.SINGLE_MAPPING_NAME)));
}
}
@Override
protected String contentType() {
return CONTENT_TYPE;
}
}