Skip to content

Commit 7da15b6

Browse files
committed
Merge branch 'master' of github.com:freshmaker74/NEST
Conflicts: src/Nest/DSL/SearchDescriptor.cs src/Nest/ElasticClient-Statics.cs
2 parents 471218d + 12811f1 commit 7da15b6

13 files changed

+500
-26
lines changed

src/Nest/DSL/Query/MultiMatchQueryDescriptor.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Nest
1313
public class MultiMatchQueryDescriptor<T> : IQuery where T : class
1414
{
1515
[JsonProperty(PropertyName = "type")]
16-
internal virtual string _Type { get { return null; } }
16+
internal virtual string _Type { get; set; }
1717

1818
[JsonProperty(PropertyName = "query")]
1919
internal string _Query { get; set; }
@@ -150,5 +150,11 @@ public MultiMatchQueryDescriptor<T> TieBreaker(double tieBreaker)
150150
this._TieBreaker = tieBreaker;
151151
return this;
152152
}
153+
154+
public MultiMatchQueryDescriptor<T> Type(TextQueryType type)
155+
{
156+
this._Type = type.ToString().ToLower();
157+
return this;
158+
}
153159
}
154160
}

src/Nest/DSL/SearchDescriptor.cs

Lines changed: 54 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ public abstract class SearchDescriptorBase
3131
public class SearchDescriptor<T> : SearchDescriptorBase where T : class
3232
{
3333
private readonly TypeNameResolver typeNameResolver;
34-
34+
3535
public SearchDescriptor()
3636
{
3737
this.typeNameResolver = new TypeNameResolver();
3838
}
3939

40-
40+
4141
internal override Type _ClrType { get { return typeof(T); } }
4242
internal Func<dynamic, Hit<dynamic>, Type> _ConcreteTypeSelector;
4343

@@ -71,7 +71,7 @@ public SearchDescriptor<T> Index(string index)
7171
public SearchDescriptor<T> Types(IEnumerable<string> types)
7272
{
7373
types.ThrowIfEmpty("types");
74-
this._Types = types.Select(s=>(TypeNameMarker)s);
74+
this._Types = types.Select(s => (TypeNameMarker)s);
7575
return this;
7676
}
7777
/// <summary>
@@ -91,7 +91,7 @@ public SearchDescriptor<T> Types(IEnumerable<Type> types)
9191
types.ThrowIfEmpty("types");
9292
this._Types = types.Select(s => (TypeNameMarker)s);
9393
return this;
94-
94+
9595
}
9696
/// <summary>
9797
/// The types to execute the search on. Defaults to the inferred typename of T
@@ -203,6 +203,9 @@ public SearchDescriptor<T> Strict(bool strict = true)
203203
[JsonConverter(typeof(DictionaryKeysAreNotPropertyNamesJsonConverter))]
204204
internal IDictionary<string, FacetDescriptorsBucket<T>> _Facets { get; set; }
205205

206+
[JsonProperty(PropertyName = "suggest")]
207+
internal IDictionary<string, SuggestDescriptorBucket<T>> _Suggest { get; set; }
208+
206209
[JsonProperty(PropertyName = "query")]
207210
internal RawOrQueryDescriptor<T> _QueryOrRaw
208211
{
@@ -252,7 +255,7 @@ internal RawOrFilterDescriptor<T> _FilterOrRaw
252255
[JsonConverter(typeof(DictionaryKeysAreNotPropertyNamesJsonConverter))]
253256
internal FluentDictionary<string, ScriptFilterDescriptor> _ScriptFields { get; set; }
254257

255-
[JsonProperty(PropertyName = "partial_fields")]
258+
[JsonProperty(PropertyName = "partial_fields")]
256259
[JsonConverter(typeof(DictionaryKeysAreNotPropertyNamesJsonConverter))]
257260
internal Dictionary<string, PartialFieldDescriptor<T>> _PartialFields { get; set; }
258261

@@ -445,30 +448,30 @@ public SearchDescriptor<T> ScriptFields(
445448
return this;
446449
}
447450

448-
public SearchDescriptor<T> PartialFields(params Action<PartialFieldDescriptor<T>>[] partialFieldDescriptor)
449-
{
450-
if (this._PartialFields == null)
451-
this._PartialFields = new Dictionary<string, PartialFieldDescriptor<T>>();
451+
public SearchDescriptor<T> PartialFields(params Action<PartialFieldDescriptor<T>>[] partialFieldDescriptor)
452+
{
453+
if (this._PartialFields == null)
454+
this._PartialFields = new Dictionary<string, PartialFieldDescriptor<T>>();
452455

453-
var descriptors = new List<PartialFieldDescriptor<T>>();
456+
var descriptors = new List<PartialFieldDescriptor<T>>();
454457

455-
foreach (var selector in partialFieldDescriptor)
456-
{
457-
var filter = new PartialFieldDescriptor<T>();
458-
selector(filter);
459-
descriptors.Add(filter);
460-
}
458+
foreach (var selector in partialFieldDescriptor)
459+
{
460+
var filter = new PartialFieldDescriptor<T>();
461+
selector(filter);
462+
descriptors.Add(filter);
463+
}
461464

462-
foreach (var d in descriptors)
463-
{
464-
var key = d._Field;
465-
if (string.IsNullOrEmpty(key))
466-
throw new DslException("Could not infer key for highlight field descriptor");
465+
foreach (var d in descriptors)
466+
{
467+
var key = d._Field;
468+
if (string.IsNullOrEmpty(key))
469+
throw new DslException("Could not infer key for highlight field descriptor");
467470

468-
this._PartialFields.Add(key, d);
469-
}
470-
return this;
471-
}
471+
this._PartialFields.Add(key, d);
472+
}
473+
return this;
474+
}
472475

473476
/// <summary>
474477
/// <para>Allows to add one or more sort on specific fields. Each sort can be reversed as well.
@@ -841,6 +844,32 @@ public SearchDescriptor<T> FacetFilter(string name, Func<FilterDescriptor<T>, Ba
841844
return this;
842845
}
843846

847+
public SearchDescriptor<T> TermSuggest(string name, Func<TermSuggestDescriptor<T>, TermSuggestDescriptor<T>> suggest)
848+
{
849+
name.ThrowIfNullOrEmpty("name");
850+
suggest.ThrowIfNull("suggest");
851+
if (this._Suggest == null)
852+
this._Suggest = new Dictionary<string, SuggestDescriptorBucket<T>>();
853+
TermSuggestDescriptor<T> desc = new TermSuggestDescriptor<T>();
854+
TermSuggestDescriptor<T> item = suggest(desc);
855+
SuggestDescriptorBucket<T> bucket = new SuggestDescriptorBucket<T> { _Text = item._Text, TermSuggest = item };
856+
this._Suggest.Add(name, bucket);
857+
return this;
858+
}
859+
860+
public SearchDescriptor<T> PhraseSuggest(string name, Func<PhraseSuggestDescriptor<T>, PhraseSuggestDescriptor<T>> suggest)
861+
{
862+
name.ThrowIfNullOrEmpty("name");
863+
suggest.ThrowIfNull("suggest");
864+
if (this._Suggest == null)
865+
this._Suggest = new Dictionary<string, SuggestDescriptorBucket<T>>();
866+
PhraseSuggestDescriptor<T> desc = new PhraseSuggestDescriptor<T>();
867+
PhraseSuggestDescriptor<T> item = suggest(desc);
868+
SuggestDescriptorBucket<T> bucket = new SuggestDescriptorBucket<T> { _Text = item._Text, PhraseSuggest = item };
869+
this._Suggest.Add(name, bucket);
870+
return this;
871+
}
872+
844873
/// <summary>
845874
/// Describe the query to perform using a query descriptor lambda
846875
/// </summary>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Nest
4+
{
5+
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
6+
public abstract class BaseSuggestDescriptor<T> : ISuggestDescriptor<T> where T : class
7+
{
8+
internal string _Text { get; set; }
9+
10+
[JsonProperty(PropertyName = "field")]
11+
internal string _Field { get; set; }
12+
13+
[JsonProperty(PropertyName = "analyzer")]
14+
internal string _Analyzer { get; set; }
15+
16+
[JsonProperty(PropertyName = "size")]
17+
internal int? _Size { get; set; }
18+
19+
[JsonProperty(PropertyName = "shard_size")]
20+
internal int? _ShardSize { get; set; }
21+
}
22+
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
using System;
2+
using System.Linq.Expressions;
3+
using Newtonsoft.Json;
4+
using Nest.Resolvers;
5+
6+
namespace Nest
7+
{
8+
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
9+
public class DirectGeneratorDescriptor<T> where T : class
10+
{
11+
[JsonProperty(PropertyName = "field")]
12+
internal string _Field { get; set; }
13+
14+
[JsonProperty(PropertyName = "size")]
15+
internal int? _Size { get; set; }
16+
17+
[JsonProperty(PropertyName = "prefix_len")]
18+
internal int? _PrefixLen { get; set; }
19+
20+
[JsonProperty(PropertyName = "suggest_mode")]
21+
internal string _SuggestMode { get; set; }
22+
23+
[JsonProperty(PropertyName = "min_word_len")]
24+
internal int? _MinWordLen { get; set; }
25+
26+
[JsonProperty(PropertyName = "max_edits")]
27+
internal int? _MaxEdits { get; set; }
28+
29+
[JsonProperty(PropertyName = "max_inspections")]
30+
internal decimal? _MaxInspections { get; set; }
31+
32+
[JsonProperty(PropertyName = "min_doc_freq")]
33+
internal decimal? _MinDocFrequency { get; set; }
34+
35+
[JsonProperty(PropertyName = "max_term_freq")]
36+
internal decimal? _MaxTermFrequency { get; set; }
37+
38+
[JsonProperty(PropertyName = "pre_filter")]
39+
internal string _PreFilter { get; set; }
40+
41+
[JsonProperty(PropertyName = "post_filter")]
42+
internal string _PostFilter { get; set; }
43+
44+
public DirectGeneratorDescriptor<T> OnField(string field)
45+
{
46+
this._Field = field;
47+
return this;
48+
}
49+
50+
public DirectGeneratorDescriptor<T> OnField(Expression<Func<T, object>> objectPath)
51+
{
52+
var fieldName = new PropertyNameResolver().Resolve(objectPath);
53+
return this.OnField(fieldName);
54+
}
55+
56+
public DirectGeneratorDescriptor<T> Size(int size)
57+
{
58+
this._Size = size;
59+
return this;
60+
}
61+
62+
public DirectGeneratorDescriptor<T> SuggestMode(SuggestMode mode)
63+
{
64+
this._SuggestMode = Enum.GetName(typeof(SuggestMode), mode).ToLower();
65+
return this;
66+
}
67+
68+
public DirectGeneratorDescriptor<T> MinWordLength(int length)
69+
{
70+
this._MinWordLen = length;
71+
return this;
72+
}
73+
74+
public DirectGeneratorDescriptor<T> PrefixLength(int length)
75+
{
76+
this._PrefixLen = length;
77+
return this;
78+
}
79+
80+
public DirectGeneratorDescriptor<T> MaxEdits(int maxEdits)
81+
{
82+
this._MaxEdits = maxEdits;
83+
return this;
84+
}
85+
86+
public DirectGeneratorDescriptor<T> MaxInspections(decimal maxInspections)
87+
{
88+
this._MaxInspections = maxInspections;
89+
return this;
90+
}
91+
92+
public DirectGeneratorDescriptor<T> MinDocFrequency(decimal frequency)
93+
{
94+
this._MinDocFrequency = frequency;
95+
return this;
96+
}
97+
98+
public DirectGeneratorDescriptor<T> MaxTermFrequency(decimal frequency)
99+
{
100+
this._MaxTermFrequency = frequency;
101+
return this;
102+
}
103+
104+
public DirectGeneratorDescriptor<T> PreFilter(string analyzer)
105+
{
106+
this._PreFilter = analyzer;
107+
return this;
108+
}
109+
110+
public DirectGeneratorDescriptor<T> PostFilter(string analyzer)
111+
{
112+
this._PostFilter = analyzer;
113+
return this;
114+
}
115+
116+
}
117+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace Nest
2+
{
3+
public interface ISuggestDescriptor<out T> : ISuggestDescriptor
4+
{
5+
6+
}
7+
public interface ISuggestDescriptor
8+
{
9+
}
10+
}

0 commit comments

Comments
 (0)