@@ -36,13 +36,13 @@ public QueryDescriptor()
3636 [ JsonProperty ( PropertyName = "ids" ) ]
3737 internal IdsQuery IdsQuery { get ; set ; }
3838 [ 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 ; }
4242 [ 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 ; }
4646 [ JsonProperty ( PropertyName = "dis_max" ) ]
4747 internal DismaxQueryDescriptor < T > DismaxQueryDescriptor { get ; set ; }
4848 [ JsonProperty ( PropertyName = "filtered" ) ]
@@ -102,7 +102,7 @@ internal QueryDescriptor<T> CreateConditionlessQueryDescriptor(IQuery query)
102102 if ( this . _Strict )
103103 throw new DslException ( "Query resulted in a conditionless {0} query (json by approx):\n "
104104 . F (
105- query . GetType ( ) . Name . Replace ( "Descriptor" , "" ) . Replace ( "`1" , "" )
105+ query . GetType ( ) . Name . Replace ( "Descriptor" , "" ) . Replace ( "`1" , "" )
106106 )
107107 ) ;
108108 return new QueryDescriptor < T > { IsConditionless = ! this . _Strict } ;
@@ -193,17 +193,35 @@ public BaseQuery TermsDescriptor(Action<TermsQueryDescriptor<T>> selector)
193193 if ( query . IsConditionless )
194194 return CreateConditionlessQueryDescriptor ( query ) ;
195195
196- this . TermsQueryDescriptor = new Dictionary < string , object > ( )
196+ if ( query . _ExternalField == null )
197197 {
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+
200214 if ( query . _MinMatch . HasValue )
201215 {
202216 this . TermsQueryDescriptor . Add ( "minimum_match" , query . _MinMatch ) ;
203217 }
204218 if ( query . _DisableCord )
205219 {
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 ) ;
207225 }
208226 return new QueryDescriptor < T > { TermsQueryDescriptor = this . TermsQueryDescriptor } ;
209227 }
@@ -587,36 +605,36 @@ public BaseQuery CustomBoostFactor(Action<CustomBoostFactorQueryDescriptor<T>> s
587605 this . CustomBoostFactorQueryDescriptor = query ;
588606 return new QueryDescriptor < T > { CustomBoostFactorQueryDescriptor = this . CustomBoostFactorQueryDescriptor } ;
589607 }
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+ }
620638 /// <summary>
621639 /// A query that matches documents matching boolean combinations of other queries. The bool query maps to
622640 /// Lucene BooleanQuery.
@@ -727,8 +745,8 @@ public BaseQuery Wildcard(Expression<Func<T, object>> fieldDescriptor
727745 /// one of the wildcards * or ?. The wildcard query maps to Lucene WildcardQuery.
728746 /// </summary>
729747 public BaseQuery Wildcard (
730- string field ,
731- string value ,
748+ string field ,
749+ string value ,
732750 double ? Boost = null ,
733751 RewriteMultiTerm ? Rewrite = null )
734752 {
@@ -764,8 +782,8 @@ public BaseQuery Prefix(Expression<Func<T, object>> fieldDescriptor
764782 /// The prefix query maps to Lucene PrefixQuery.
765783 /// </summary>
766784 public BaseQuery Prefix (
767- string field ,
768- string value ,
785+ string field ,
786+ string value ,
769787 double ? Boost = null ,
770788 RewriteMultiTerm ? Rewrite = null )
771789 {
0 commit comments