From 685c473728cd657c864e310c62582e4fa8204ba9 Mon Sep 17 00:00:00 2001 From: Juan Date: Wed, 20 Nov 2013 08:51:53 +1300 Subject: [PATCH 1/2] Added both the Preferred and Custom preference --- .../Search/SearchOptions/SearchOptionTests.cs | 20 ++++++ src/Nest/DSL/SearchDescriptor.cs | 61 ++++++++++++++----- 2 files changed, 67 insertions(+), 14 deletions(-) diff --git a/src/Nest.Tests.Unit/Search/SearchOptions/SearchOptionTests.cs b/src/Nest.Tests.Unit/Search/SearchOptions/SearchOptionTests.cs index 5595b9c518f..5688725ea41 100644 --- a/src/Nest.Tests.Unit/Search/SearchOptions/SearchOptionTests.cs +++ b/src/Nest.Tests.Unit/Search/SearchOptions/SearchOptionTests.cs @@ -120,6 +120,26 @@ public void TestExecuteOnNode() StringAssert.Contains("preference=_only_node:somenode", result.ConnectionStatus.RequestUrl); } [Test] + public void TestExecuteOnCustomNode() + { + var s = new SearchDescriptor() + .From(0) + .Size(10) + .ExecuteOnCustomNode("somenode"); + var result = this._client.Search(s); + StringAssert.Contains("preference=somenode", result.ConnectionStatus.RequestUrl); + } + [Test] + public void TestExecuteOnPreferredNode() + { + var s = new SearchDescriptor() + .From(0) + .Size(10) + .ExecuteOnPreferredNode("somenode"); + var result = this._client.Search(s); + StringAssert.Contains("preference=_prefer_node:somenode", result.ConnectionStatus.RequestUrl); + } + [Test] public void TestFields() { var s = new SearchDescriptor() diff --git a/src/Nest/DSL/SearchDescriptor.cs b/src/Nest/DSL/SearchDescriptor.cs index b20995e7337..484d8ce0fba 100644 --- a/src/Nest/DSL/SearchDescriptor.cs +++ b/src/Nest/DSL/SearchDescriptor.cs @@ -28,7 +28,7 @@ public abstract class SearchDescriptorBase internal Func, Type> _ConcreteTypeSelector; - + } [JsonObject(MemberSerialization = MemberSerialization.OptIn)] @@ -412,6 +412,39 @@ public SearchDescriptor ExecuteOnNode(string node) return this; } /// + /// + /// Controls a preference of which shard replicas to execute the search request on. + /// By default, the operation is randomized between the each shard replicas. + /// + /// + /// A custom value will be used to guarantee that the same shards will be used for + /// the same custom value. This can help with "jumping values" when hitting different + /// shards in different refresh states. A sample value can be something like the + /// web session id, or the user name. + /// + /// + public SearchDescriptor ExecuteOnCustomNode(string node) + { + node.ThrowIfNull("node"); + this._Preference = node; + return this; + } + /// + /// + /// Controls a preference of which shard replicas to execute the search request on. + /// By default, the operation is randomized between the each shard replicas. + /// + /// + /// Prefers execution on the node with the provided node id if applicable. + /// + /// + public SearchDescriptor ExecuteOnPreferredNode(string node) + { + node.ThrowIfNull("node"); + this._Preference = string.Format("_prefer_node:{0}", node); + return this; + } + /// /// Allows to configure different boost level per index when searching across /// more than one indices. This is very handy when hits coming from one index /// matter more than hits coming from another index (think social graph where each user has an index). @@ -888,18 +921,18 @@ public SearchDescriptor PhraseSuggest(string name, Func CompletionSuggest(string name, Func, CompletionSuggestDescriptor> suggest) - { - name.ThrowIfNullOrEmpty("name"); - suggest.ThrowIfNull("suggest"); - if (this._Suggest == null) - this._Suggest = new Dictionary>(); - CompletionSuggestDescriptor desc = new CompletionSuggestDescriptor(); - CompletionSuggestDescriptor item = suggest(desc); - SuggestDescriptorBucket bucket = new SuggestDescriptorBucket { _Text = item._Text, CompletionSuggest = item }; - this._Suggest.Add(name, bucket); - return this; - } + public SearchDescriptor CompletionSuggest(string name, Func, CompletionSuggestDescriptor> suggest) + { + name.ThrowIfNullOrEmpty("name"); + suggest.ThrowIfNull("suggest"); + if (this._Suggest == null) + this._Suggest = new Dictionary>(); + CompletionSuggestDescriptor desc = new CompletionSuggestDescriptor(); + CompletionSuggestDescriptor item = suggest(desc); + SuggestDescriptorBucket bucket = new SuggestDescriptorBucket { _Text = item._Text, CompletionSuggest = item }; + this._Suggest.Add(name, bucket); + return this; + } /// /// Describe the query to perform using a query descriptor lambda @@ -907,7 +940,7 @@ public SearchDescriptor CompletionSuggest(string name, Func Query(Func, BaseQuery> query) { query.ThrowIfNull("query"); - var q = new QueryDescriptor() {IsStrict = this._Strict}; + var q = new QueryDescriptor() { IsStrict = this._Strict }; var bq = query(q); return this.Query(bq); From 77a52db830168990203a94768633ac0b373b3030 Mon Sep 17 00:00:00 2001 From: Juan Date: Wed, 20 Nov 2013 09:33:51 +1300 Subject: [PATCH 2/2] Removed ExecuteOnCustomNode, same as Preference. --- .../Search/SearchOptions/SearchOptionTests.cs | 10 ---------- src/Nest/DSL/SearchDescriptor.cs | 18 ------------------ 2 files changed, 28 deletions(-) diff --git a/src/Nest.Tests.Unit/Search/SearchOptions/SearchOptionTests.cs b/src/Nest.Tests.Unit/Search/SearchOptions/SearchOptionTests.cs index 5688725ea41..38cfbcb8893 100644 --- a/src/Nest.Tests.Unit/Search/SearchOptions/SearchOptionTests.cs +++ b/src/Nest.Tests.Unit/Search/SearchOptions/SearchOptionTests.cs @@ -120,16 +120,6 @@ public void TestExecuteOnNode() StringAssert.Contains("preference=_only_node:somenode", result.ConnectionStatus.RequestUrl); } [Test] - public void TestExecuteOnCustomNode() - { - var s = new SearchDescriptor() - .From(0) - .Size(10) - .ExecuteOnCustomNode("somenode"); - var result = this._client.Search(s); - StringAssert.Contains("preference=somenode", result.ConnectionStatus.RequestUrl); - } - [Test] public void TestExecuteOnPreferredNode() { var s = new SearchDescriptor() diff --git a/src/Nest/DSL/SearchDescriptor.cs b/src/Nest/DSL/SearchDescriptor.cs index 484d8ce0fba..d43195c4481 100644 --- a/src/Nest/DSL/SearchDescriptor.cs +++ b/src/Nest/DSL/SearchDescriptor.cs @@ -417,24 +417,6 @@ public SearchDescriptor ExecuteOnNode(string node) /// By default, the operation is randomized between the each shard replicas. /// /// - /// A custom value will be used to guarantee that the same shards will be used for - /// the same custom value. This can help with "jumping values" when hitting different - /// shards in different refresh states. A sample value can be something like the - /// web session id, or the user name. - /// - /// - public SearchDescriptor ExecuteOnCustomNode(string node) - { - node.ThrowIfNull("node"); - this._Preference = node; - return this; - } - /// - /// - /// Controls a preference of which shard replicas to execute the search request on. - /// By default, the operation is randomized between the each shard replicas. - /// - /// /// Prefers execution on the node with the provided node id if applicable. /// ///