@@ -36,13 +36,13 @@ public QueryDescriptor()
36
36
[ JsonProperty ( PropertyName = "ids" ) ]
37
37
internal IdsQuery IdsQuery { get ; set ; }
38
38
[ JsonProperty ( PropertyName = "custom_score" ) ]
39
- internal CustomScoreQueryDescriptor < T > CustomScoreQueryDescriptor { get ; set ; }
40
- [ JsonProperty ( PropertyName = "custom_filters_score" ) ]
41
- internal CustomFiltersScoreDescriptor < T > CustomFiltersScoreQueryDescriptor { get ; set ; }
39
+ internal CustomScoreQueryDescriptor < T > CustomScoreQueryDescriptor { get ; set ; }
40
+ [ JsonProperty ( PropertyName = "custom_filters_score" ) ]
41
+ internal CustomFiltersScoreDescriptor < T > CustomFiltersScoreQueryDescriptor { get ; set ; }
42
42
[ JsonProperty ( PropertyName = "custom_boost_factor" ) ]
43
- internal CustomBoostFactorQueryDescriptor < T > CustomBoostFactorQueryDescriptor { get ; set ; }
44
- [ JsonProperty ( PropertyName = "constant_score" ) ]
45
- internal ConstantScoreQueryDescriptor < T > ConstantScoreQueryDescriptor { get ; set ; }
43
+ internal CustomBoostFactorQueryDescriptor < T > CustomBoostFactorQueryDescriptor { get ; set ; }
44
+ [ JsonProperty ( PropertyName = "constant_score" ) ]
45
+ internal ConstantScoreQueryDescriptor < T > ConstantScoreQueryDescriptor { get ; set ; }
46
46
[ JsonProperty ( PropertyName = "dis_max" ) ]
47
47
internal DismaxQueryDescriptor < T > DismaxQueryDescriptor { get ; set ; }
48
48
[ JsonProperty ( PropertyName = "filtered" ) ]
@@ -102,7 +102,7 @@ internal QueryDescriptor<T> CreateConditionlessQueryDescriptor(IQuery query)
102
102
if ( this . _Strict )
103
103
throw new DslException ( "Query resulted in a conditionless {0} query (json by approx):\n "
104
104
. F (
105
- query . GetType ( ) . Name . Replace ( "Descriptor" , "" ) . Replace ( "`1" , "" )
105
+ query . GetType ( ) . Name . Replace ( "Descriptor" , "" ) . Replace ( "`1" , "" )
106
106
)
107
107
) ;
108
108
return new QueryDescriptor < T > { IsConditionless = ! this . _Strict } ;
@@ -193,17 +193,35 @@ public BaseQuery TermsDescriptor(Action<TermsQueryDescriptor<T>> selector)
193
193
if ( query . IsConditionless )
194
194
return CreateConditionlessQueryDescriptor ( query ) ;
195
195
196
- this . TermsQueryDescriptor = new Dictionary < string , object > ( )
196
+ if ( query . _ExternalField == null )
197
197
{
198
- { query . _Field , query . _Terms }
199
- } ;
198
+ this . TermsQueryDescriptor = new Dictionary < string , object > ( )
199
+ {
200
+ { query . _Field , query . _Terms }
201
+ } ;
202
+ }
203
+ else
204
+ {
205
+ if ( query . _ExternalField . _Id . IsNullOrEmpty ( ) )
206
+ throw new DslException ( "terms query external field has no id set" ) ;
207
+
208
+ this . TermsQueryDescriptor = new Dictionary < string , object > ( )
209
+ {
210
+ { query . _Field , query . _ExternalField }
211
+ } ;
212
+ }
213
+
200
214
if ( query . _MinMatch . HasValue )
201
215
{
202
216
this . TermsQueryDescriptor . Add ( "minimum_match" , query . _MinMatch ) ;
203
217
}
204
218
if ( query . _DisableCord )
205
219
{
206
- this . TermsQueryDescriptor . Add ( "disable_coord" , query . _DisableCord ) ;
220
+ this . TermsQueryDescriptor . Add ( "disable_coord" , query . _DisableCord ) ;
221
+ }
222
+ if ( ! query . _CacheKey . IsNullOrEmpty ( ) )
223
+ {
224
+ this . TermsQueryDescriptor . Add ( "_cache_key" , query . _CacheKey ) ;
207
225
}
208
226
return new QueryDescriptor < T > { TermsQueryDescriptor = this . TermsQueryDescriptor } ;
209
227
}
@@ -587,36 +605,36 @@ public BaseQuery CustomBoostFactor(Action<CustomBoostFactorQueryDescriptor<T>> s
587
605
this . CustomBoostFactorQueryDescriptor = query ;
588
606
return new QueryDescriptor < T > { CustomBoostFactorQueryDescriptor = this . CustomBoostFactorQueryDescriptor } ;
589
607
}
590
- /// <summary>
591
- /// custom_score query allows to wrap another query and customize the scoring of it optionally with a
592
- /// computation derived from other field values in the doc (numeric ones) using script expression
593
- /// </summary>
594
- public BaseQuery CustomScore ( Action < CustomScoreQueryDescriptor < T > > customScoreQuery )
595
- {
596
- var query = new CustomScoreQueryDescriptor < T > ( ) ;
597
- customScoreQuery ( query ) ;
598
-
599
- if ( query . IsConditionless )
600
- return CreateConditionlessQueryDescriptor ( query ) ;
601
-
602
- this . CustomScoreQueryDescriptor = query ;
603
- return new QueryDescriptor < T > { CustomScoreQueryDescriptor = this . CustomScoreQueryDescriptor } ;
604
- }
605
- /// <summary>
606
- /// custom_score query allows to wrap another query and customize the scoring of it optionally with a
607
- /// computation derived from other field values in the doc (numeric ones) using script or boost expression
608
- /// </summary>
609
- public BaseQuery CustomFiltersScore ( Action < CustomFiltersScoreDescriptor < T > > customFiltersScoreQuery )
610
- {
611
- var query = new CustomFiltersScoreDescriptor < T > ( ) ;
612
- customFiltersScoreQuery ( query ) ;
613
-
614
- if ( query . IsConditionless )
615
- return CreateConditionlessQueryDescriptor ( query ) ;
616
-
617
- this . CustomFiltersScoreQueryDescriptor = query ;
618
- return new QueryDescriptor < T > { CustomFiltersScoreQueryDescriptor = this . CustomFiltersScoreQueryDescriptor } ;
619
- }
608
+ /// <summary>
609
+ /// custom_score query allows to wrap another query and customize the scoring of it optionally with a
610
+ /// computation derived from other field values in the doc (numeric ones) using script expression
611
+ /// </summary>
612
+ public BaseQuery CustomScore ( Action < CustomScoreQueryDescriptor < T > > customScoreQuery )
613
+ {
614
+ var query = new CustomScoreQueryDescriptor < T > ( ) ;
615
+ customScoreQuery ( query ) ;
616
+
617
+ if ( query . IsConditionless )
618
+ return CreateConditionlessQueryDescriptor ( query ) ;
619
+
620
+ this . CustomScoreQueryDescriptor = query ;
621
+ return new QueryDescriptor < T > { CustomScoreQueryDescriptor = this . CustomScoreQueryDescriptor } ;
622
+ }
623
+ /// <summary>
624
+ /// custom_score query allows to wrap another query and customize the scoring of it optionally with a
625
+ /// computation derived from other field values in the doc (numeric ones) using script or boost expression
626
+ /// </summary>
627
+ public BaseQuery CustomFiltersScore ( Action < CustomFiltersScoreDescriptor < T > > customFiltersScoreQuery )
628
+ {
629
+ var query = new CustomFiltersScoreDescriptor < T > ( ) ;
630
+ customFiltersScoreQuery ( query ) ;
631
+
632
+ if ( query . IsConditionless )
633
+ return CreateConditionlessQueryDescriptor ( query ) ;
634
+
635
+ this . CustomFiltersScoreQueryDescriptor = query ;
636
+ return new QueryDescriptor < T > { CustomFiltersScoreQueryDescriptor = this . CustomFiltersScoreQueryDescriptor } ;
637
+ }
620
638
/// <summary>
621
639
/// A query that matches documents matching boolean combinations of other queries. The bool query maps to
622
640
/// Lucene BooleanQuery.
@@ -727,8 +745,8 @@ public BaseQuery Wildcard(Expression<Func<T, object>> fieldDescriptor
727
745
/// one of the wildcards * or ?. The wildcard query maps to Lucene WildcardQuery.
728
746
/// </summary>
729
747
public BaseQuery Wildcard (
730
- string field ,
731
- string value ,
748
+ string field ,
749
+ string value ,
732
750
double ? Boost = null ,
733
751
RewriteMultiTerm ? Rewrite = null )
734
752
{
@@ -764,8 +782,8 @@ public BaseQuery Prefix(Expression<Func<T, object>> fieldDescriptor
764
782
/// The prefix query maps to Lucene PrefixQuery.
765
783
/// </summary>
766
784
public BaseQuery Prefix (
767
- string field ,
768
- string value ,
785
+ string field ,
786
+ string value ,
769
787
double ? Boost = null ,
770
788
RewriteMultiTerm ? Rewrite = null )
771
789
{
0 commit comments