Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/Nest/DSL/SuggestDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,20 @@ protected override void UpdatePathInfo(IConnectionSettingsValues settings, Elast
SuggestPathInfo.Update(pathInfo, this);
}

protected override void SetRouteParameters(IConnectionSettingsValues settings, ElasticsearchPathInfo<SuggestRequestParameters> pathInfo)
{
var inferrer = new ElasticInferrer(settings);

var index = inferrer.IndexName<T>();
pathInfo.Index = index;

if (Self.Indices.HasAny())
pathInfo.Index = inferrer.IndexNames(Self.Indices);
else
pathInfo.Index = Self.AllIndices.GetValueOrDefault(false) ? null : inferrer.IndexName<T>();

if (pathInfo.Index.IsNullOrEmpty())
pathInfo.Index = "_all";
}
}
}
7 changes: 4 additions & 3 deletions src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -552,9 +552,10 @@
<Compile Include="Search\Source\SourceTests.cs" />
<Compile Include="Search\Sorting\FunctionScoreTests.cs" />
<Compile Include="Search\Sorting\SortTests.cs" />
<Compile Include="Search\suggest\CompletionSuggestTests.cs" />
<Compile Include="Search\suggest\PhraseSuggestTests.cs" />
<Compile Include="Search\suggest\TermSuggestTests.cs" />
<Compile Include="Search\Suggest\CompletionSuggestTests.cs" />
<Compile Include="Search\Suggest\PhraseSuggestTests.cs" />
<Compile Include="Search\Suggest\SuggestUrlTest.cs" />
<Compile Include="Search\Suggest\TermSuggestTests.cs" />
<Compile Include="Settings\UsePrettyResponseTests.cs" />
<Compile Include="TestElasticClient.cs" />
<Compile Include="Core\Update\UpdateTests.cs" />
Expand Down
73 changes: 73 additions & 0 deletions src/Tests/Nest.Tests.Unit/Search/suggest/SuggestUrlTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System;
using System.Net;
using Elasticsearch.Net.Connection;
using Elasticsearch.Net.ConnectionPool;
using FluentAssertions;
using Nest.Tests.MockData.Domain;
using NUnit.Framework;

namespace Nest.Tests.Unit.Search.Suggest
{
[TestFixture]
public class SuggestUrlTest
{
private void TestUrl(string expected, Func<SuggestDescriptor<ElasticsearchProject>, SuggestDescriptor<ElasticsearchProject>> descriptor, ConnectionSettings settings = null)
{
var client = new ElasticClient(settings, new InMemoryConnection());
var response = client.Suggest(descriptor);
var uri = new Uri(response.ConnectionStatus.RequestUrl);
var actual = WebUtility.UrlDecode(uri.AbsolutePath);
actual.Should().Be(expected);
}

[Test]
public void Suggest_to_all_url_test()
{
TestUrl(
expected: "/_all/_suggest",
descriptor: d => d.Term("name", s => s.OnField(f => f.Contributors)).AllIndices()
);
}

[Test]
public void Suggest_to_specific_index_url_test()
{
var settings = new ConnectionSettings(new SingleNodeConnectionPool(new Uri("http://esserver.com")));

settings.MapDefaultTypeIndices(d => d
.Add(typeof (ElasticsearchProject), typeof (ElasticsearchProject).Name.ToLower()));

TestUrl(
expected: "/elasticsearchproject/_suggest",
descriptor: d => d.Term("name", s => s.OnField(f => f.Contributors)),
settings: settings
);
}

[Test]
public void Suggest_to_specific_index_specified_in_descriptor_url_test()
{
var settings = new ConnectionSettings(new SingleNodeConnectionPool(new Uri("http://esserver.com")));

settings.MapDefaultTypeIndices(d => d
.Add(typeof (ElasticsearchVersionInfo), "elasticsearchproject"));

TestUrl(
expected: "/elasticsearchproject/_suggest",
descriptor: d => d.Term("name", s => s.OnField(f => f.Contributors)).Index<ElasticsearchVersionInfo>(),
settings: settings
);
}

[Test]
public void Suggest_to_specific_index_specified_as_string_in_descriptor_url_test()
{
var settings = new ConnectionSettings(new SingleNodeConnectionPool(new Uri("http://esserver.com")));

TestUrl(
expected: "/anotherindex/_suggest",
descriptor: d => d.Term("name", s => s.OnField(f => f.Contributors)).Index("anotherindex")
);
}
}
}