Example #1
0
        /// <summary>
        /// The completion suggester is a so-called prefix suggester.
        /// It does not do spell correction like the term or phrase suggesters but allows basic auto-complete functionality.
        /// </summary>
        public SuggestDescriptor <T> Completion(string name, Func <CompletionSuggesterDescriptor <T>, CompletionSuggesterDescriptor <T> > suggest)
        {
            name.ThrowIfNullOrEmpty(nameof(name));
            suggest.ThrowIfNull(nameof(suggest));

            var desc = new CompletionSuggesterDescriptor <T>();
            var item = suggest(desc);

            Self.Suggest.Add(name, item);
            return(this);
        }
Example #2
0
        /// <summary>
        /// The completion suggester is a so-called prefix suggester.
        /// It does not do spell correction like the term or phrase suggesters but allows basic auto-complete functionality.
        /// </summary>
        public SearchDescriptor <T> SuggestCompletion(string name, Func <CompletionSuggesterDescriptor <T>, CompletionSuggesterDescriptor <T> > suggest) => Assign(a => {
            name.ThrowIfNullOrEmpty(nameof(name));
            suggest.ThrowIfNull(nameof(suggest));
            if (a.Suggest == null)
            {
                a.Suggest = new Dictionary <string, ISuggestBucket>();
            }

            var desc = new CompletionSuggesterDescriptor <T>();
            var item = suggest(desc);
            ICompletionSuggester i = item;
            var bucket             = new SuggestBucket {
                Text = i.Text, Completion = item
            };
            a.Suggest.Add(name, bucket);
        });