/* 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.Runtime.Serialization;
using OpenSearch.Net;
using OpenSearch.Net.Utf8Json;
namespace OpenSearch.Client
{
///
/// An operation to define the calculation of
/// term vectors when using Multi termvectors API
///
public interface IMultiTermVectorOperation
{
///
/// A document not indexed in OpenSearch,
/// to generate term vectors for
///
[DataMember(Name = "doc")]
[JsonFormatter(typeof(SourceFormatter<>))]
object Document { get; set; }
///
/// Whether to include field statistics. When set to false,
///
/// - document count (how many documents contain this field)
///
/// - sum of document frequencies (the sum of document frequencies for all terms in this field)
///
/// - sum of total term frequencies (the sum of total term frequencies of each term in this field)
///
/// will be omitted. Default is true.
///
[DataMember(Name = "field_statistics")]
bool? FieldStatistics { get; set; }
///
/// Filter terms based on their tf-idf scores.
/// This can be useful in order find out a good characteristic
/// vector of a document.
///
[DataMember(Name = "filter")]
ITermVectorFilter Filter { get; set; }
///
/// The id of the document
///
[DataMember(Name = "_id")]
Id Id { get; set; }
///
/// The index in which the document resides
///
[DataMember(Name = "_index")]
IndexName Index { get; set; }
///
/// Whether to include the start and end offsets.
/// Default is true.
///
[DataMember(Name = "offsets")]
bool? Offsets { get; set; }
///
/// Whether to include the term payloads as
/// base64 encoded bytes. Default is true
///
[DataMember(Name = "payloads")]
bool? Payloads { get; set; }
///
/// Whether to include the term positions.
/// Default is true
///
[DataMember(Name = "positions")]
bool? Positions { get; set; }
///
/// When requesting term vectors for ,
/// a shard to get the statistics from is randomly selected.
/// Use only to hit a particular shard.
///
[DataMember(Name = "routing")]
Routing Routing { get; set; }
///
/// The document field to generate term
/// vectors for
///
[DataMember(Name = "fields")]
Fields Fields { get; set; }
///
/// Whether to include term statistics. When set to true,
///
/// - total term frequency (how often a term occurs in all documents)
///
/// - document frequency (the number of documents containing the current term)
///
/// will be returned. Default is false since
/// term statistics can have a large performance impact.
///
[DataMember(Name = "term_statistics")]
bool? TermStatistics { get; set; }
///
/// The version number
///
[DataMember(Name = "version")]
long? Version { get; set; }
///
/// The type of version
///
[DataMember(Name = "version_type")]
VersionType? VersionType { get; set; }
}
///
public class MultiTermVectorOperation : IMultiTermVectorOperation
where T : class
{
private Routing _routing;
public MultiTermVectorOperation(Id id)
{
Id = id;
Index = typeof(T);
}
///
public object Document { get; set; }
///
public bool? FieldStatistics { get; set; }
///
public ITermVectorFilter Filter { get; set; }
///
public Id Id { get; set; }
///
public IndexName Index { get; set; }
///
public bool? Offsets { get; set; }
///
public bool? Payloads { get; set; }
///
public bool? Positions { get; set; }
///
public Routing Routing
{
get => _routing ?? (Document == null ? null : new Routing(Document));
set => _routing = value;
}
///
public Fields Fields { get; set; }
///
public bool? TermStatistics { get; set; }
///
public long? Version { get; set; }
///
public VersionType? VersionType { get; set; }
}
///
public class MultiTermVectorOperationDescriptor
: DescriptorBase, IMultiTermVectorOperation>, IMultiTermVectorOperation
where T : class
{
private Routing _routing;
object IMultiTermVectorOperation.Document { get; set; }
bool? IMultiTermVectorOperation.FieldStatistics { get; set; }
ITermVectorFilter IMultiTermVectorOperation.Filter { get; set; }
Id IMultiTermVectorOperation.Id { get; set; }
IndexName IMultiTermVectorOperation.Index { get; set; } = typeof(T);
bool? IMultiTermVectorOperation.Offsets { get; set; }
bool? IMultiTermVectorOperation.Payloads { get; set; }
bool? IMultiTermVectorOperation.Positions { get; set; }
Routing IMultiTermVectorOperation.Routing
{
get => _routing ?? (Self.Document == null ? null : new Routing(Self.Document));
set => _routing = value;
}
Fields IMultiTermVectorOperation.Fields { get; set; }
bool? IMultiTermVectorOperation.TermStatistics { get; set; }
long? IMultiTermVectorOperation.Version { get; set; }
VersionType? IMultiTermVectorOperation.VersionType { get; set; }
///
public MultiTermVectorOperationDescriptor Fields(Func, IPromise> fields) =>
Assign(fields, (a, v) => a.Fields = v?.Invoke(new FieldsDescriptor())?.Value);
///
public MultiTermVectorOperationDescriptor Fields(Fields fields) => Assign(fields, (a, v) => a.Fields = v);
///
public MultiTermVectorOperationDescriptor Id(Id id) => Assign(id, (a, v) => a.Id = v);
///
public MultiTermVectorOperationDescriptor Index(IndexName index) => Assign(index, (a, v) => a.Index = v);
///
public MultiTermVectorOperationDescriptor Document(T document) => Assign(document, (a, v) => a.Document = v);
///
public MultiTermVectorOperationDescriptor Offsets(bool? offsets = true) => Assign(offsets, (a, v) => a.Offsets = v);
///
public MultiTermVectorOperationDescriptor Payloads(bool? payloads = true) => Assign(payloads, (a, v) => a.Payloads = v);
///
public MultiTermVectorOperationDescriptor Positions(bool? positions = true) => Assign(positions, (a, v) => a.Positions = v);
///
public MultiTermVectorOperationDescriptor TermStatistics(bool? termStatistics = true) => Assign(termStatistics, (a, v) => a.TermStatistics = v);
///
public MultiTermVectorOperationDescriptor FieldStatistics(bool? fieldStatistics = true) =>
Assign(fieldStatistics, (a, v) => a.FieldStatistics = v);
///
public MultiTermVectorOperationDescriptor Filter(Func filterSelector) =>
Assign(filterSelector, (a, v) => a.Filter = v?.Invoke(new TermVectorFilterDescriptor()));
///
public MultiTermVectorOperationDescriptor Version(long? version) => Assign(version, (a, v) => a.Version = v);
///
public MultiTermVectorOperationDescriptor VersionType(VersionType? versionType) => Assign(versionType, (a, v) => a.VersionType = v);
///
public MultiTermVectorOperationDescriptor Routing(Routing routing) => Assign(routing, (a, v) => a.Routing = v);
}
}