/// <summary> /// The term suggester suggests terms based on edit distance. The provided suggest text is analyzed before terms are suggested. /// The suggested terms are provided per analyzed suggest text token. The term suggester doesn’t take the query into account that is part of request. /// </summary> public SuggestDescriptor <T> Term(string name, Func <TermSuggestDescriptor <T>, TermSuggestDescriptor <T> > suggest) { name.ThrowIfNullOrEmpty("name"); suggest.ThrowIfNull("suggest"); var desc = new TermSuggestDescriptor <T>(); var item = suggest(desc); Self.Suggest.Add(name, item); return(this); }
///// <summary> ///// To avoid repetition of the suggest text, it is possible to define a global text. ///// </summary> //public SearchDescriptor<T> SuggestGlobalText(string globalSuggestText) //{ // if (Self.Suggest == null) // Self.Suggest = new Dictionary<string, ISuggester>(); // Self.Suggest.Add("text", globalSuggestText); // return this; //} /// <summary> /// The term suggester suggests terms based on edit distance. The provided suggest text is analyzed before terms are suggested. /// The suggested terms are provided per analyzed suggest text token. The term suggester doesn’t take the query into account that is part of request. /// </summary> public SearchDescriptor <T> SuggestTerm(string name, Func <TermSuggestDescriptor <T>, TermSuggestDescriptor <T> > suggest) { name.ThrowIfNullOrEmpty("name"); suggest.ThrowIfNull("suggest"); if (Self.Suggest == null) { Self.Suggest = new Dictionary <string, ISuggestBucket>(); } var desc = new TermSuggestDescriptor <T>(); var item = suggest(desc); ITermSuggester i = item; var bucket = new SuggestBucket { Text = i.Text, Term = item }; Self.Suggest.Add(name, bucket); return(this); }
public void TermSuggestDescriptorTest() { var termSuggestDescriptor = new TermSuggestDescriptor<ElasticSearchProject>() .MaxEdits(3) .MaxInspections(17) .OnField("field1") .Size(3) .SuggestMode(SuggestMode.Missing); var json = TestElasticClient.Serialize(termSuggestDescriptor); var expected = @"{ ""suggest_mode"": ""missing"", ""max_edits"": 3, ""max_inspections"": 17, ""field"": ""field1"", ""size"": 3 }"; Assert.True(json.JsonEquals(expected), json); }
public void TermSuggestDescriptorTest() { var termSuggestDescriptor = new TermSuggestDescriptor <ElasticsearchProject>() .MaxEdits(3) .MaxInspections(17) .OnField("field1") .Size(3) .SuggestMode(SuggestMode.Missing); var json = TestElasticClient.Serialize(termSuggestDescriptor); var expected = @"{ ""suggest_mode"": ""missing"", ""max_edits"": 3, ""max_inspections"": 17, ""field"": ""field1"", ""size"": 3 }"; Assert.True(json.JsonEquals(expected), json); }