Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute;
import org.opensearch.index.analysis.NamedAnalyzer;
import org.opensearch.index.query.QueryShardContext;
import org.opensearch.search.lookup.SearchLookup;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import static org.opensearch.common.xcontent.support.XContentMapValues.nodeIntegerValue;
/**
* A {@link FieldMapper} that takes a string and writes a count of the tokens in that string
* to the index. In most ways the mapper acts just like an {@link NumberFieldMapper}.
*/
public class TokenCountFieldMapper extends ParametrizedFieldMapper {
public static final String CONTENT_TYPE = "token_count";
private static TokenCountFieldMapper toType(FieldMapper in) {
return (TokenCountFieldMapper) in;
}
public static class Builder extends ParametrizedFieldMapper.Builder {
private final Parameter index = Parameter.indexParam(m -> toType(m).index, true);
private final Parameter hasDocValues = Parameter.docValuesParam(m -> toType(m).hasDocValues, true);
private final Parameter store = Parameter.storeParam(m -> toType(m).store, false);
private final Parameter analyzer = Parameter.analyzerParam("analyzer", true, m -> toType(m).analyzer, () -> null);
private final Parameter nullValue = new Parameter<>(
"null_value",
false,
() -> null,
(n, c, o) -> o == null ? null : nodeIntegerValue(o),
m -> toType(m).nullValue
).acceptsNull();
private final Parameter enablePositionIncrements = Parameter.boolParam(
"enable_position_increments",
false,
m -> toType(m).enablePositionIncrements,
true
);
private final Parameter