/* 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.Utf8Json; namespace OpenSearch.Client { /// /// An indexed or artificial document with which to find likeness /// [InterfaceDataContract] [ReadAs(typeof(LikeDocument))] public interface ILikeDocument { /// /// A document to find other documents like /// [DataMember(Name = "doc")] [JsonFormatter(typeof(SourceFormatter))] object Document { get; set; } /// /// The fields to use for likeness /// [DataMember(Name = "fields")] Fields Fields { get; set; } /// /// The id of an indexed document to find other documents like /// [DataMember(Name = "_id")] Id Id { get; set; } /// /// The index of an indexed document to find other documents like /// [DataMember(Name = "_index")] IndexName Index { get; set; } /// /// A different analyzer than the one defined for the target fields /// [DataMember(Name = "per_field_analyzer")] IPerFieldAnalyzer PerFieldAnalyzer { get; set; } /// /// The routing value of an indexed document to find other documents like /// [DataMember(Name = "routing")] Routing Routing { get; set; } } /// public abstract class LikeDocumentBase : ILikeDocument { /// public object Document { get; set; } /// public Fields Fields { get; set; } /// public Id Id { get; set; } /// public IndexName Index { get; set; } /// public IPerFieldAnalyzer PerFieldAnalyzer { get; set; } /// public Routing Routing { get; set; } } /// public class LikeDocument : LikeDocumentBase where TDocument : class { internal LikeDocument() { } public LikeDocument(Id id) { Id = id; Index = typeof(TDocument); } public LikeDocument(TDocument document) { Document = document; Index = typeof(TDocument); } } /// public class LikeDocumentDescriptor : DescriptorBase, ILikeDocument>, ILikeDocument where TDocument : class { public LikeDocumentDescriptor() => Self.Index = typeof(TDocument); object ILikeDocument.Document { get; set; } Fields ILikeDocument.Fields { get; set; } Id ILikeDocument.Id { get; set; } IndexName ILikeDocument.Index { get; set; } IPerFieldAnalyzer ILikeDocument.PerFieldAnalyzer { get; set; } Routing ILikeDocument.Routing { get; set; } /// public LikeDocumentDescriptor Index(IndexName index) => Assign(index, (a, v) => a.Index = v); /// public LikeDocumentDescriptor Id(Id id) => Assign(id, (a, v) => a.Id = v); /// public LikeDocumentDescriptor Routing(Routing routing) => Assign(routing, (a, v) => a.Routing = v); /// public LikeDocumentDescriptor Fields(Func, IPromise> fields) => Assign(fields, (a, v) => a.Fields = v?.Invoke(new FieldsDescriptor())?.Value); /// public LikeDocumentDescriptor Fields(Fields fields) => Assign(fields, (a, v) => a.Fields = v); /// public LikeDocumentDescriptor Document(TDocument document) => Assign(document, (a, v) => a.Document = v); /// public LikeDocumentDescriptor PerFieldAnalyzer( Func, IPromise> analyzerSelector ) => Assign(analyzerSelector, (a, v) => a.PerFieldAnalyzer = v?.Invoke(new PerFieldAnalyzerDescriptor())?.Value); } }