Skip to content

Commit

Permalink
Attribute SuggestBucket for serialization #3763
Browse files Browse the repository at this point in the history
  • Loading branch information
codebrain committed May 30, 2019
1 parent 184440d commit 1e6890f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Nest/Search/Suggesters/SuggestBucket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,22 @@ public interface ISuggestBucket

public class SuggestBucket : ISuggestBucket
{
[DataMember(Name = "completion")]
public ICompletionSuggester Completion { get; set; }

[DataMember(Name = "phrase")]
public IPhraseSuggester Phrase { get; set; }

[DataMember(Name = "prefix")]
public string Prefix { get; set; }

[DataMember(Name = "regex")]
public string Regex { get; set; }

[DataMember(Name = "term")]
public ITermSuggester Term { get; set; }

[DataMember(Name = "text")]
public string Text { get; set; }
}
}
47 changes: 47 additions & 0 deletions src/Tests/Tests.Reproduce/Discuss179634.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Globalization;
using System.Text;
using Elastic.Xunit.XunitPlumbing;
using Elasticsearch.Net;
using FluentAssertions;
using FluentAssertions.Common;
using Nest;
using Newtonsoft.Json.Linq;
using Tests.Core.Client;
using Tests.Core.Extensions;
using Tests.Core.Serialization;
using Tests.Domain;

namespace Tests.Reproduce
{
public class Discuss179634
{
[U]
public void SerializeCompletionSuggesterFieldsCorrectlyWhenDefaultFieldNameInferrerUsed()
{
var connectionPool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
var settings = new ConnectionSettings(connectionPool, new InMemoryConnection())
.DefaultFieldNameInferrer(p => p.ToUpper(CultureInfo.CurrentCulture))
.DisableDirectStreaming();

var tester = new SerializationTester(new ElasticClient(settings));

var suggest = new SearchDescriptor<Project>()
.Suggest(ss => ss
.Completion("title", cs => cs
.Field(f => f.Suggest)
.Prefix("keyword")
.Fuzzy(f => f
.Fuzziness(Fuzziness.Auto)
)
.Size(5)
)
);

var expected = @"{""suggest"":{""title"":{""completion"":{""fuzzy"":{""fuzziness"":""AUTO""},""field"":""SUGGEST"",""size"":5},""prefix"":""keyword""}}}";

var result = tester.Serializes(suggest, expected);
result.Success.Should().Be(true, result.DiffFromExpected);
}
}
}

0 comments on commit 1e6890f

Please sign in to comment.