1
1
using System ;
2
2
using System . Collections . Generic ;
3
+ using System . Globalization ;
3
4
using System . Linq ;
4
5
using Nest . Resolvers . Converters ;
5
6
using Newtonsoft . Json ;
@@ -49,6 +50,25 @@ public interface IMoreLikeThisQuery : IQuery
49
50
50
51
[ JsonProperty ( PropertyName = "analyzer" ) ]
51
52
string Analyzer { get ; set ; }
53
+
54
+ /// <summary>
55
+ /// A list of document ids. This parameter is required if like_text is not specified.
56
+ /// The texts are fetched from fields unless specified in each doc, and cannot be set to _all.
57
+ /// <pre>Available from Elasticsearch 1.3.0</pre>
58
+ /// </summary>
59
+ [ JsonProperty ( "ids" ) ]
60
+ IEnumerable < string > Ids { get ; set ; }
61
+
62
+ /// <summary>
63
+ /// A list of documents following the same syntax as the Multi GET API. This parameter is required if like_text is not specified.
64
+ /// The texts are fetched from fields unless specified in each doc, and cannot be set to _all.
65
+ /// <pre>Available from Elasticsearch 1.3.0</pre>
66
+ /// </summary>
67
+ [ JsonProperty ( "docs" ) ]
68
+ IEnumerable < IMultiGetOperation > Documents { get ; set ; }
69
+
70
+ [ JsonProperty ( PropertyName = "include" ) ]
71
+ bool ? Include { get ; set ; }
52
72
}
53
73
54
74
@@ -73,11 +93,15 @@ protected override void WrapInContainer(IQueryContainer container)
73
93
public double ? BoostTerms { get ; set ; }
74
94
public double ? Boost { get ; set ; }
75
95
public string Analyzer { get ; set ; }
96
+ public IEnumerable < string > Ids { get ; set ; }
97
+ public IEnumerable < IMultiGetOperation > Documents { get ; set ; }
98
+ public bool ? Include { get ; set ; }
76
99
}
77
100
78
-
79
101
public class MoreLikeThisQueryDescriptor < T > : IMoreLikeThisQuery where T : class
80
102
{
103
+ private IMoreLikeThisQuery Self { get { return this ; } }
104
+
81
105
IEnumerable < PropertyPathMarker > IMoreLikeThisQuery . Fields { get ; set ; }
82
106
83
107
string IMoreLikeThisQuery . LikeText { get ; set ; }
@@ -103,87 +127,133 @@ public class MoreLikeThisQueryDescriptor<T> : IMoreLikeThisQuery where T : class
103
127
double ? IMoreLikeThisQuery . Boost { get ; set ; }
104
128
105
129
string IMoreLikeThisQuery . Analyzer { get ; set ; }
130
+
131
+ IEnumerable < string > IMoreLikeThisQuery . Ids { get ; set ; }
132
+
133
+ IEnumerable < IMultiGetOperation > IMoreLikeThisQuery . Documents { get ; set ; }
134
+
135
+ bool ? IMoreLikeThisQuery . Include { get ; set ; }
106
136
107
137
bool IQuery . IsConditionless
108
138
{
109
139
get
110
140
{
111
- return ( ( IMoreLikeThisQuery ) this ) . LikeText . IsNullOrEmpty ( ) ;
141
+ return this . Self . LikeText . IsNullOrEmpty ( ) ;
112
142
}
113
143
}
114
144
115
145
public MoreLikeThisQueryDescriptor < T > OnFields ( IEnumerable < string > fields )
116
146
{
117
- ( ( IMoreLikeThisQuery ) this ) . Fields = fields . Select ( f=> ( PropertyPathMarker ) f ) ;
147
+ this . Self . Fields = fields . Select ( f=> ( PropertyPathMarker ) f ) ;
118
148
return this ;
119
149
}
120
150
public MoreLikeThisQueryDescriptor < T > OnFields (
121
151
params Expression < Func < T , object > > [ ] objectPaths )
122
152
{
123
- ( ( IMoreLikeThisQuery ) this ) . Fields = objectPaths . Select ( e=> ( PropertyPathMarker ) e ) ;
153
+ this . Self . Fields = objectPaths . Select ( e=> ( PropertyPathMarker ) e ) ;
124
154
return this ;
125
155
}
126
156
public MoreLikeThisQueryDescriptor < T > LikeText ( string likeText )
127
157
{
128
- ( ( IMoreLikeThisQuery ) this ) . LikeText = likeText ;
158
+ this . Self . LikeText = likeText ;
129
159
return this ;
130
160
}
131
161
public MoreLikeThisQueryDescriptor < T > StopWords ( IEnumerable < string > stopWords )
132
162
{
133
- ( ( IMoreLikeThisQuery ) this ) . StopWords = stopWords ;
163
+ this . Self . StopWords = stopWords ;
134
164
return this ;
135
165
}
136
166
137
167
public MoreLikeThisQueryDescriptor < T > MaxQueryTerms ( int maxQueryTerms )
138
168
{
139
- ( ( IMoreLikeThisQuery ) this ) . MaxQueryTerms = maxQueryTerms ;
169
+ this . Self . MaxQueryTerms = maxQueryTerms ;
140
170
return this ;
141
171
}
142
172
public MoreLikeThisQueryDescriptor < T > MinTermFrequency ( int minTermFrequency )
143
173
{
144
- ( ( IMoreLikeThisQuery ) this ) . MinTermFrequency = minTermFrequency ;
174
+ this . Self . MinTermFrequency = minTermFrequency ;
145
175
return this ;
146
176
}
147
177
public MoreLikeThisQueryDescriptor < T > MinDocumentFrequency ( int minDocumentFrequency )
148
178
{
149
- ( ( IMoreLikeThisQuery ) this ) . MinDocumentFrequency = minDocumentFrequency ;
179
+ this . Self . MinDocumentFrequency = minDocumentFrequency ;
150
180
return this ;
151
181
}
152
182
public MoreLikeThisQueryDescriptor < T > MaxDocumentFrequency ( int maxDocumentFrequency )
153
183
{
154
- ( ( IMoreLikeThisQuery ) this ) . MaxDocumentFrequency = maxDocumentFrequency ;
184
+ this . Self . MaxDocumentFrequency = maxDocumentFrequency ;
155
185
return this ;
156
186
}
157
187
public MoreLikeThisQueryDescriptor < T > MinWordLength ( int minWordLength )
158
188
{
159
- ( ( IMoreLikeThisQuery ) this ) . MinWordLength = minWordLength ;
189
+ this . Self . MinWordLength = minWordLength ;
160
190
return this ;
161
191
}
162
192
public MoreLikeThisQueryDescriptor < T > MaxWordLength ( int maxWordLength )
163
193
{
164
- ( ( IMoreLikeThisQuery ) this ) . MaxWordLength = maxWordLength ;
194
+ this . Self . MaxWordLength = maxWordLength ;
165
195
return this ;
166
196
}
167
197
public MoreLikeThisQueryDescriptor < T > BoostTerms ( double boostTerms )
168
198
{
169
- ( ( IMoreLikeThisQuery ) this ) . BoostTerms = boostTerms ;
199
+ this . Self . BoostTerms = boostTerms ;
170
200
return this ;
171
201
}
172
202
public MoreLikeThisQueryDescriptor < T > TermMatchPercentage ( double termMatchPercentage )
173
203
{
174
- ( ( IMoreLikeThisQuery ) this ) . TermMatchPercentage = termMatchPercentage ;
204
+ this . Self . TermMatchPercentage = termMatchPercentage ;
175
205
return this ;
176
206
}
177
207
public MoreLikeThisQueryDescriptor < T > Boost ( double boost )
178
208
{
179
- ( ( IMoreLikeThisQuery ) this ) . Boost = boost ;
209
+ this . Self . Boost = boost ;
180
210
return this ;
181
211
}
182
212
public MoreLikeThisQueryDescriptor < T > Analyzer ( string analyzer )
183
213
{
184
- ( ( IMoreLikeThisQuery ) this ) . Analyzer = analyzer ;
214
+ this . Self . Analyzer = analyzer ;
215
+ return this ;
216
+ }
217
+
218
+ public MoreLikeThisQueryDescriptor < T > Ids ( IEnumerable < long > ids )
219
+ {
220
+ this . Self . Ids = ids . Select ( i=> i . ToString ( CultureInfo . InvariantCulture ) ) ;
185
221
return this ;
186
222
}
187
223
224
+ public MoreLikeThisQueryDescriptor < T > Ids ( IEnumerable < string > ids )
225
+ {
226
+ this . Self . Ids = ids ;
227
+ return this ;
228
+ }
229
+
230
+ /// <summary>
231
+ /// Specify multiple documents to suply the more like this like text
232
+ /// </summary>
233
+ public MoreLikeThisQueryDescriptor < T > Documents ( Func < MoreLikeThisQueryDocumentsDescriptor < T > , MoreLikeThisQueryDocumentsDescriptor < T > > getDocumentsSelector )
234
+ {
235
+ getDocumentsSelector . ThrowIfNull ( "getDocumentsSelector" ) ;
236
+
237
+ var descriptor = getDocumentsSelector ( new MoreLikeThisQueryDocumentsDescriptor < T > ( true ) ) ;
238
+ descriptor . ThrowIfNull ( "descriptor" ) ;
239
+ Self . Documents = descriptor . GetOperations ;
240
+ return this ;
241
+ }
242
+
243
+ /// <summary>
244
+ /// Specify multiple documents to supply the more like this text, but do not generate index: and type: on the get operations.
245
+ /// Useful if the node has rest.action.multi.allow_explicit_index set to false
246
+ /// </summary>
247
+ /// <param name="getDocumentsSelector"></param>
248
+ /// <returns></returns>
249
+ public MoreLikeThisQueryDescriptor < T > DocumentsExplicit ( Func < MoreLikeThisQueryDocumentsDescriptor < T > , MoreLikeThisQueryDocumentsDescriptor < T > > getDocumentsSelector )
250
+ {
251
+ getDocumentsSelector . ThrowIfNull ( "getDocumentsSelector" ) ;
252
+
253
+ var descriptor = getDocumentsSelector ( new MoreLikeThisQueryDocumentsDescriptor < T > ( false ) ) ;
254
+ descriptor . ThrowIfNull ( "descriptor" ) ;
255
+ Self . Documents = descriptor . GetOperations ;
256
+ return this ;
257
+ }
188
258
}
189
259
}
0 commit comments