/* 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.Runtime.Serialization; using OpenSearch.Net.Utf8Json; namespace OpenSearch.Client { /// /// The completion suggester provides auto-complete/search-as-you-type functionality. /// This is a navigational feature to guide users to relevant results as they are typing, improving search precision. /// It is not meant for spell correction or did-you-mean functionality like the term or phrase suggesters. /// [InterfaceDataContract] [ReadAs(typeof(CompletionSuggester))] public interface ICompletionSuggester : ISuggester { /// /// Context mappings used to filter and/or boost suggestions /// [DataMember(Name = "contexts")] IDictionary> Contexts { get; set; } /// /// Support fuzziness for the suggestions /// [DataMember(Name = "fuzzy")] ISuggestFuzziness Fuzzy { get; set; } /// /// Prefix used to search for suggestions /// [IgnoreDataMember] string Prefix { get; set; } /// /// Prefix as a regular expression used to search for suggestions /// [IgnoreDataMember] string Regex { get; set; } /// /// Whether duplicate suggestions should be filtered out. Defaults to false /// [DataMember(Name = "skip_duplicates")] bool? SkipDuplicates { get; set; } } /// public class CompletionSuggester : SuggesterBase, ICompletionSuggester { /// public IDictionary> Contexts { get; set; } /// public ISuggestFuzziness Fuzzy { get; set; } /// public string Prefix { get; set; } /// public string Regex { get; set; } /// public bool? SkipDuplicates { get; set; } } /// public class CompletionSuggesterDescriptor : SuggestDescriptorBase, ICompletionSuggester, T>, ICompletionSuggester where T : class { IDictionary> ICompletionSuggester.Contexts { get; set; } ISuggestFuzziness ICompletionSuggester.Fuzzy { get; set; } string ICompletionSuggester.Prefix { get; set; } string ICompletionSuggester.Regex { get; set; } bool? ICompletionSuggester.SkipDuplicates { get; set; } /// public CompletionSuggesterDescriptor Prefix(string prefix) => Assign(prefix, (a, v) => a.Prefix = v); /// public CompletionSuggesterDescriptor Regex(string regex) => Assign(regex, (a, v) => a.Regex = v); /// public CompletionSuggesterDescriptor Fuzzy(Func, ISuggestFuzziness> selector = null) => Assign(selector.InvokeOrDefault(new SuggestFuzzinessDescriptor()), (a, v) => a.Fuzzy = v); /// public CompletionSuggesterDescriptor Contexts( Func, IPromise>>> contexts ) => Assign(contexts, (a, v) => a.Contexts = v?.Invoke(new SuggestContextQueriesDescriptor()).Value); /// public CompletionSuggesterDescriptor SkipDuplicates(bool? skipDuplicates = true) => Assign(skipDuplicates, (a, v) => a.SkipDuplicates = v); } }