Skip to content

Commit abc37e7

Browse files
committed
added a unit test for the completion suggest on the search
1 parent e12b900 commit abc37e7

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/Nest.Tests.Unit/Search/suggest/CompletionSuggestTests.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,36 @@ public void CompletionSuggestDescriptorFuzzyTest()
7373

7474
Assert.IsTrue(json.JsonEquals(expected), json);
7575
}
76+
77+
[Test]
78+
public void CompletionSuggestOnSearchTest()
79+
{
80+
var search = this._client.Search<ElasticSearchProject>(s => s
81+
.SuggestCompletion("mycompletionsuggest", ts => ts
82+
.Text("n")
83+
.OnField(p=>p.Name)
84+
.Fuzzy()
85+
)
86+
);
87+
88+
var expected = @"{
89+
suggest: {
90+
mycompletionsuggest: {
91+
text: ""n"",
92+
completion: {
93+
fuzzy: {
94+
edit_distance: 1,
95+
transpositions: true,
96+
min_length: 3,
97+
prefix_length: 1
98+
},
99+
field: ""name""
100+
}
101+
}
102+
}
103+
}";
104+
var json = search.ConnectionStatus.Request;
105+
Assert.True(json.JsonEquals(expected), json);
106+
}
76107
}
77108
}

src/Nest/DSL/SearchDescriptor.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,11 @@ public SearchDescriptor<T> SuggestGlobalText(string globalSuggestText)
888888
return this;
889889
}
890890

891+
892+
/// <summary>
893+
/// The term suggester suggests terms based on edit distance. The provided suggest text is analyzed before terms are suggested.
894+
/// 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.
895+
/// </summary>
891896
public SearchDescriptor<T> SuggestTerm(string name, Func<TermSuggestDescriptor<T>, TermSuggestDescriptor<T>> suggest)
892897
{
893898
name.ThrowIfNullOrEmpty("name");
@@ -901,6 +906,10 @@ public SearchDescriptor<T> SuggestTerm(string name, Func<TermSuggestDescriptor<T
901906
return this;
902907
}
903908

909+
/// <summary>
910+
/// The phrase suggester adds additional logic on top of the term suggester to select entire corrected phrases
911+
/// instead of individual tokens weighted based on ngram-langugage models.
912+
/// </summary>
904913
public SearchDescriptor<T> SuggestPhrase(string name, Func<PhraseSuggestDescriptor<T>, PhraseSuggestDescriptor<T>> suggest)
905914
{
906915
name.ThrowIfNullOrEmpty("name");
@@ -915,6 +924,10 @@ public SearchDescriptor<T> SuggestPhrase(string name, Func<PhraseSuggestDescript
915924
return this;
916925
}
917926

927+
/// <summary>
928+
/// The completion suggester is a so-called prefix suggester.
929+
/// It does not do spell correction like the term or phrase suggesters but allows basic auto-complete functionality.
930+
/// </summary>
918931
public SearchDescriptor<T> SuggestCompletion(string name, Func<CompletionSuggestDescriptor<T>, CompletionSuggestDescriptor<T>> suggest)
919932
{
920933
name.ThrowIfNullOrEmpty("name");

0 commit comments

Comments
 (0)