/* 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.
*/
/*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. 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.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Runtime.Serialization;
namespace OpenSearch.Client.Specification.IndicesApi
{
[MapsApi("indices.analyze.json")]
[ReadAs(typeof(AnalyzeRequest))]
public partial interface IAnalyzeRequest
{
///The name of the analyzer to use
[DataMember(Name ="analyzer")]
string Analyzer { get; set; }
///Filter only certain token attributes to be returned
[DataMember(Name ="attributes")]
IEnumerable Attributes { get; set; }
///A collection of character filters to use for the analysis
[DataMember(Name ="char_filter")]
AnalyzeCharFilters CharFilter { get; set; }
///Return more details, and output the analyzer chain per step in the process
[DataMember(Name ="explain")]
bool? Explain { get; set; }
///Use the analyzer configured for this field (instead of passing the analyzer name)
[DataMember(Name ="field")]
Field Field { get; set; }
///A collection of filters to use for the analysis
[DataMember(Name ="filter")]
AnalyzeTokenFilters Filter { get; set; }
///The name of the normalizer to use
[DataMember(Name ="normalizer")]
string Normalizer { get; set; }
///The text on which the analysis should be performed (when request body is not used)
[DataMember(Name ="text")]
IEnumerable Text { get; set; }
///The name of the tokenizer to use for the analysis
[DataMember(Name ="tokenizer")]
Union Tokenizer { get; set; }
}
public partial class AnalyzeRequest
{
public AnalyzeRequest(IndexName indices, string textToAnalyze)
: this(indices) => Text = new[] { textToAnalyze };
///
public string Analyzer { get; set; }
///
public IEnumerable Attributes { get; set; }
///
public AnalyzeCharFilters CharFilter { get; set; }
///
public bool? Explain { get; set; }
///
public Field Field { get; set; }
///
public AnalyzeTokenFilters Filter { get; set; }
///
public string Normalizer { get; set; }
///
public IEnumerable Text { get; set; }
///
public Union Tokenizer { get; set; }
}
public partial class AnalyzeDescriptor
{
string IAnalyzeRequest.Analyzer { get; set; }
IEnumerable IAnalyzeRequest.Attributes { get; set; }
AnalyzeCharFilters IAnalyzeRequest.CharFilter { get; set; }
bool? IAnalyzeRequest.Explain { get; set; }
Field IAnalyzeRequest.Field { get; set; }
AnalyzeTokenFilters IAnalyzeRequest.Filter { get; set; }
string IAnalyzeRequest.Normalizer { get; set; }
IEnumerable IAnalyzeRequest.Text { get; set; }
Union IAnalyzeRequest.Tokenizer { get; set; }
///The name of the tokenizer to use for the analysis
public AnalyzeDescriptor Tokenizer(string tokenizer) => Assign(tokenizer, (a, v) => a.Tokenizer = v);
///An inline definition of a tokenizer
public AnalyzeDescriptor Tokenizer(Func tokenizer) =>
Assign(tokenizer, (a, v) =>
{
var u = v?.Invoke(new AnalyzeTokenizersSelector());
if (u != null) a.Tokenizer = new Union(u);
});
///The name of the analyzer to use
public AnalyzeDescriptor Analyzer(string analyser) => Assign(analyser, (a, v) => a.Analyzer = v);
///A collection of character filters to use for the analysis
public AnalyzeDescriptor CharFilter(params string[] charFilter) => Assign(charFilter, (a, v) => a.CharFilter = v);
///A collection of character filters to use for the analysis
public AnalyzeDescriptor CharFilter(IEnumerable charFilter) => Assign(charFilter.ToArray(), (a, v) => a.CharFilter = v);
///A collection of character filters to use for the analysis
public AnalyzeDescriptor CharFilter(Func> charFilters) =>
Assign(charFilters, (a, v) => a.CharFilter = v?.Invoke(new AnalyzeCharFiltersDescriptor())?.Value);
///A collection of filters to use for the analysis
public AnalyzeDescriptor Filter(params string[] filter) => Assign(filter, (a, v) => a.Filter = v);
///A collection of filters to use for the analysis
public AnalyzeDescriptor Filter(IEnumerable filter) => Assign(filter.ToArray(), (a, v) => a.Filter = v);
///A collection of filters to use for the analysis
public AnalyzeDescriptor Filter(Func> tokenFilters) =>
Assign(tokenFilters, (a, v) => a.Filter = v?.Invoke(new AnalyzeTokenFiltersDescriptor())?.Value);
///The name of the normalizer to use
public AnalyzeDescriptor Normalizer(string normalizer) => Assign(normalizer, (a, v) => a.Normalizer = v);
///Use the analyzer configured for this field (instead of passing the analyzer name)
public AnalyzeDescriptor Field(Field field) => Assign(field, (a, v) => a.Field = v);
///Use the analyzer configured for this field (instead of passing the analyzer name)
public AnalyzeDescriptor Field(Expression> field) => Assign(field, (a, v) => a.Field = v);
///Use the analyzer configured for this field (instead of passing the analyzer name)
public AnalyzeDescriptor Field(Expression> field) => Assign(field, (a, v) => a.Field = v);
///The text on which the analysis should be performed
public AnalyzeDescriptor Text(params string[] text) => Assign(text, (a, v) => a.Text = v);
///The text on which the analysis should be performed
public AnalyzeDescriptor Text(IEnumerable text) => Assign(text, (a, v) => a.Text = v);
///Return more details, and output the analyzer chain per step in the process
public AnalyzeDescriptor Explain(bool? explain = true) => Assign(explain, (a, v) => a.Explain = v);
///Filter only certain token attributes to be returned
public AnalyzeDescriptor Attributes(params string[] attributes) => Assign(attributes, (a, v) => a.Attributes = v);
///Filter only certain token attributes to be returned
public AnalyzeDescriptor Attributes(IEnumerable attributes) => Assign(attributes.ToArray(), (a, v) => a.Attributes = v);
}
}