@@ -2612,12 +2612,20 @@ private void OnUpdateDocumentResponse(RESTConnector.Request req, RESTConnector.R
2612
2612
/// <param name="customData">A Dictionary<string, object> of data that will be passed to the callback. The raw
2613
2613
/// json output from the REST call will be passed in this object as the value of the 'json'
2614
2614
/// key.</string></param>
2615
- public bool FederatedQuery ( SuccessCallback < QueryResponse > successCallback , FailCallback failCallback , string environmentId , List < string > collectionIds , string filter = null , string query = null , string naturalLanguageQuery = null , string aggregation = null , long ? count = null , List < string > returnFields = null , long ? offset = null , List < string > sort = null , bool ? highlight = null , bool ? deduplicate = null , string deduplicateField = null , bool ? similar = null , List < string > similarDocumentIds = null , List < string > similarFields = null , bool ? passages = null , List < string > passagesFields = null , long ? passagesCount = null , long ? passagesCharacters = null , Dictionary < string , object > customData = null )
2615
+ public bool FederatedQuery ( SuccessCallback < QueryResponse > successCallback , FailCallback failCallback , string environmentId , List < string > collectionIds , string filter = null , string query = null , string naturalLanguageQuery = null , string aggregation = null , long ? count = null , List < string > returnFields = null , long ? offset = null , List < string > sort = null , bool ? highlight = null , bool ? deduplicate = null , string deduplicateField = null , bool ? similar = null , List < string > similarDocumentIds = null , List < string > similarFields = null , bool ? passages = null , List < string > passagesFields = null , long ? passagesCount = null , long ? passagesCharacters = null , string bias = null , string loggingOptOut = null , Dictionary < string , object > customData = null )
2616
2616
{
2617
2617
if ( successCallback == null )
2618
2618
throw new ArgumentNullException ( "successCallback" ) ;
2619
2619
if ( failCallback == null )
2620
2620
throw new ArgumentNullException ( "failCallback" ) ;
2621
+ if ( string . IsNullOrEmpty ( environmentId ) )
2622
+ {
2623
+ throw new ArgumentNullException ( "environmentId" ) ;
2624
+ }
2625
+ if ( collectionIds == null || collectionIds . Count < 1 )
2626
+ {
2627
+ throw new ArgumentNullException ( "collectionId" ) ;
2628
+ }
2621
2629
2622
2630
FederatedQueryRequestObj req = new FederatedQueryRequestObj ( ) ;
2623
2631
req . SuccessCallback = successCallback ;
@@ -2631,44 +2639,41 @@ public bool FederatedQuery(SuccessCallback<QueryResponse> successCallback, FailC
2631
2639
}
2632
2640
}
2633
2641
req . Parameters [ "version" ] = VersionDate ;
2634
- if ( collectionIds != null )
2635
- req . Parameters [ "collection_ids" ] = collectionIds != null && collectionIds . Count > 0 ? string . Join ( "," , collectionIds . ToArray ( ) ) : null ;
2636
- if ( ! string . IsNullOrEmpty ( filter ) )
2637
- req . Parameters [ "filter" ] = filter ;
2638
- if ( ! string . IsNullOrEmpty ( query ) )
2639
- req . Parameters [ "query" ] = query ;
2640
- if ( ! string . IsNullOrEmpty ( naturalLanguageQuery ) )
2641
- req . Parameters [ "natural_language_query" ] = naturalLanguageQuery ;
2642
- if ( ! string . IsNullOrEmpty ( aggregation ) )
2643
- req . Parameters [ "aggregation" ] = aggregation ;
2644
- if ( count != null )
2645
- req . Parameters [ "count" ] = count ;
2646
- if ( returnFields != null )
2647
- req . Parameters [ "return" ] = returnFields != null && returnFields . Count > 0 ? string . Join ( "," , returnFields . ToArray ( ) ) : null ;
2648
- if ( offset != null )
2649
- req . Parameters [ "offset" ] = offset ;
2650
- if ( sort != null )
2651
- req . Parameters [ "sort" ] = sort != null && sort . Count > 0 ? string . Join ( "," , sort . ToArray ( ) ) : null ;
2652
- if ( highlight != null )
2653
- req . Parameters [ "highlight" ] = highlight ;
2654
- if ( deduplicate != null )
2655
- req . Parameters [ "deduplicate" ] = deduplicate ;
2656
- if ( ! string . IsNullOrEmpty ( deduplicateField ) )
2657
- req . Parameters [ "deduplicate.field" ] = deduplicateField ;
2658
- if ( similar != null )
2659
- req . Parameters [ "similar" ] = similar ;
2660
- if ( similarDocumentIds != null )
2661
- req . Parameters [ "similar.document_ids" ] = similarDocumentIds != null && similarDocumentIds . Count > 0 ? string . Join ( "," , similarDocumentIds . ToArray ( ) ) : null ;
2662
- if ( similarFields != null )
2663
- req . Parameters [ "similar.fields" ] = similarFields != null && similarFields . Count > 0 ? string . Join ( "," , similarFields . ToArray ( ) ) : null ;
2664
- if ( passages != null )
2665
- req . Parameters [ "passages" ] = passages ;
2666
- if ( passagesFields != null )
2667
- req . Parameters [ "passages.fields" ] = passagesFields != null && passagesFields . Count > 0 ? string . Join ( "," , passagesFields . ToArray ( ) ) : null ;
2668
- if ( passagesCount != null )
2669
- req . Parameters [ "passages.count" ] = passagesCount ;
2670
- if ( passagesCharacters != null )
2671
- req . Parameters [ "passages.characters" ] = passagesCharacters ;
2642
+ if ( loggingOptOut != null )
2643
+ {
2644
+ req . Headers . Add ( "X-Watson-Logging-Opt-Out" , loggingOptOut . ToString ( ) ) ;
2645
+ }
2646
+ req . Headers [ "Content-Type" ] = "application/json" ;
2647
+
2648
+ QueryLarge queryLarge = new QueryLarge ( )
2649
+ {
2650
+ Filter = filter ,
2651
+ Query = query ,
2652
+ NaturalLanguageQuery = naturalLanguageQuery ,
2653
+ Passages = passages ,
2654
+ Aggregation = aggregation ,
2655
+ Count = count ,
2656
+ ReturnFields = ( returnFields == null || returnFields . Count < 1 ) ? null : string . Join ( ", " , returnFields . ToArray ( ) ) ,
2657
+ Offset = offset ,
2658
+ Sort = ( sort == null || sort . Count < 1 ) ? null : string . Join ( ", " , sort . ToArray ( ) ) ,
2659
+ Highlight = highlight ,
2660
+ PassagesFields = ( passagesFields == null || passagesFields . Count < 1 ) ? null : string . Join ( ", " , passagesFields . ToArray ( ) ) ,
2661
+ PassagesCount = passagesCount ,
2662
+ PassagesCharacters = passagesCharacters ,
2663
+ Deduplicate = deduplicate ,
2664
+ DeduplicateField = deduplicateField ,
2665
+ CollectionIds = ( collectionIds == null || collectionIds . Count < 1 ) ? null : string . Join ( ", " , collectionIds . ToArray ( ) ) ,
2666
+ Similar = similar ,
2667
+ SimilarDocumentIds = ( similarDocumentIds == null || similarDocumentIds . Count < 1 ) ? null : string . Join ( ", " , similarDocumentIds . ToArray ( ) ) ,
2668
+ SimilarFields = ( similarFields == null || similarFields . Count < 1 ) ? null : string . Join ( ", " , similarFields . ToArray ( ) ) ,
2669
+ Bias = bias
2670
+ } ;
2671
+
2672
+ fsData data = null ;
2673
+ _serializer . TrySerialize ( queryLarge , out data ) ;
2674
+ string json = data . ToString ( ) . Replace ( '\" ' , '"' ) ;
2675
+ req . Send = Encoding . UTF8 . GetBytes ( json ) ;
2676
+
2672
2677
req . OnResponse = OnFederatedQueryResponse ;
2673
2678
2674
2679
RESTConnector connector = RESTConnector . GetConnector ( Credentials , string . Format ( "/v1/environments/{0}/query" , environmentId ) ) ;
@@ -2969,7 +2974,7 @@ private void OnFederatedQueryNoticesResponse(RESTConnector.Request req, RESTConn
2969
2974
/// <param name="customData">A Dictionary<string, object> of data that will be passed to the callback. The raw
2970
2975
/// json output from the REST call will be passed in this object as the value of the 'json'
2971
2976
/// key.</string></param>
2972
- public bool Query ( SuccessCallback < QueryResponse > successCallback , FailCallback failCallback , string environmentId , string collectionId , string filter = null , string query = null , string naturalLanguageQuery = null , bool ? passages = null , string aggregation = null , long ? count = null , List < string > returnFields = null , long ? offset = null , List < string > sort = null , bool ? highlight = null , List < string > passagesFields = null , long ? passagesCount = null , long ? passagesCharacters = null , bool ? deduplicate = null , string deduplicateField = null , bool ? similar = null , List < string > similarDocumentIds = null , List < string > similarFields = null , bool ? loggingOptOut = null , Dictionary < string , object > customData = null )
2977
+ public bool Query ( SuccessCallback < QueryResponse > successCallback , FailCallback failCallback , string environmentId , string collectionId , string filter = null , string query = null , string naturalLanguageQuery = null , bool ? passages = null , string aggregation = null , long ? count = null , List < string > returnFields = null , long ? offset = null , List < string > sort = null , bool ? highlight = null , List < string > passagesFields = null , long ? passagesCount = null , long ? passagesCharacters = null , bool ? deduplicate = null , string deduplicateField = null , bool ? similar = null , List < string > similarDocumentIds = null , List < string > similarFields = null , string bias = null , bool ? loggingOptOut = null , Dictionary < string , object > customData = null )
2973
2978
{
2974
2979
if ( successCallback == null )
2975
2980
throw new ArgumentNullException ( "successCallback" ) ;
@@ -2989,43 +2994,39 @@ public bool Query(SuccessCallback<QueryResponse> successCallback, FailCallback f
2989
2994
}
2990
2995
req . Parameters [ "version" ] = VersionDate ;
2991
2996
if ( loggingOptOut != null )
2992
- req . Headers [ "X-Watson-Logging-Opt-Out" ] = loggingOptOut . ToString ( ) ;
2993
- if ( ! string . IsNullOrEmpty ( filter ) )
2994
- req . Parameters [ "filter" ] = filter ;
2995
- if ( ! string . IsNullOrEmpty ( query ) )
2996
- req . Parameters [ "query" ] = query ;
2997
- if ( ! string . IsNullOrEmpty ( naturalLanguageQuery ) )
2998
- req . Parameters [ "natural_language_query" ] = naturalLanguageQuery ;
2999
- if ( passages != null )
3000
- req . Parameters [ "passages" ] = passages ;
3001
- if ( ! string . IsNullOrEmpty ( aggregation ) )
3002
- req . Parameters [ "aggregation" ] = aggregation ;
3003
- if ( count != null )
3004
- req . Parameters [ "count" ] = count ;
3005
- if ( returnFields != null )
3006
- req . Parameters [ "return" ] = returnFields != null && returnFields . Count > 0 ? string . Join ( "," , returnFields . ToArray ( ) ) : null ;
3007
- if ( offset != null )
3008
- req . Parameters [ "offset" ] = offset ;
3009
- if ( sort != null )
3010
- req . Parameters [ "sort" ] = sort != null && sort . Count > 0 ? string . Join ( "," , sort . ToArray ( ) ) : null ;
3011
- if ( highlight != null )
3012
- req . Parameters [ "highlight" ] = highlight ;
3013
- if ( passagesFields != null )
3014
- req . Parameters [ "passages.fields" ] = passagesFields != null && passagesFields . Count > 0 ? string . Join ( "," , passagesFields . ToArray ( ) ) : null ;
3015
- if ( passagesCount != null )
3016
- req . Parameters [ "passages.count" ] = passagesCount ;
3017
- if ( passagesCharacters != null )
3018
- req . Parameters [ "passages.characters" ] = passagesCharacters ;
3019
- if ( deduplicate != null )
3020
- req . Parameters [ "deduplicate" ] = deduplicate ;
3021
- if ( ! string . IsNullOrEmpty ( deduplicateField ) )
3022
- req . Parameters [ "deduplicate.field" ] = deduplicateField ;
3023
- if ( similar != null )
3024
- req . Parameters [ "similar" ] = similar ;
3025
- if ( similarDocumentIds != null )
3026
- req . Parameters [ "similar.document_ids" ] = similarDocumentIds != null && similarDocumentIds . Count > 0 ? string . Join ( "," , similarDocumentIds . ToArray ( ) ) : null ;
3027
- if ( similarFields != null )
3028
- req . Parameters [ "similar.fields" ] = similarFields != null && similarFields . Count > 0 ? string . Join ( "," , similarFields . ToArray ( ) ) : null ;
2997
+ {
2998
+ req . Headers . Add ( "X-Watson-Logging-Opt-Out" , loggingOptOut . ToString ( ) ) ;
2999
+ }
3000
+ req . Headers [ "Content-Type" ] = "application/json" ;
3001
+
3002
+ QueryLarge queryLarge = new QueryLarge ( )
3003
+ {
3004
+ Filter = filter ,
3005
+ Query = query ,
3006
+ NaturalLanguageQuery = naturalLanguageQuery ,
3007
+ Passages = passages ,
3008
+ Aggregation = aggregation ,
3009
+ Count = count ,
3010
+ ReturnFields = ( returnFields == null || returnFields . Count < 1 ) ? null : string . Join ( ", " , returnFields . ToArray ( ) ) ,
3011
+ Offset = offset ,
3012
+ Sort = ( sort == null || sort . Count < 1 ) ? null : string . Join ( ", " , sort . ToArray ( ) ) ,
3013
+ Highlight = highlight ,
3014
+ PassagesFields = ( passagesFields == null || passagesFields . Count < 1 ) ? null : string . Join ( ", " , passagesFields . ToArray ( ) ) ,
3015
+ PassagesCount = passagesCount ,
3016
+ PassagesCharacters = passagesCharacters ,
3017
+ Deduplicate = deduplicate ,
3018
+ DeduplicateField = deduplicateField ,
3019
+ Similar = similar ,
3020
+ SimilarDocumentIds = ( similarDocumentIds == null || similarDocumentIds . Count < 1 ) ? null : string . Join ( ", " , similarDocumentIds . ToArray ( ) ) ,
3021
+ SimilarFields = ( similarFields == null || similarFields . Count < 1 ) ? null : string . Join ( ", " , similarFields . ToArray ( ) ) ,
3022
+ Bias = bias
3023
+ } ;
3024
+
3025
+ fsData data = null ;
3026
+ _serializer . TrySerialize ( queryLarge , out data ) ;
3027
+ string json = data . ToString ( ) . Replace ( '\" ' , '"' ) ;
3028
+ req . Send = Encoding . UTF8 . GetBytes ( json ) ;
3029
+
3029
3030
req . OnResponse = OnQueryResponse ;
3030
3031
3031
3032
RESTConnector connector = RESTConnector . GetConnector ( Credentials , string . Format ( "/v1/environments/{0}/collections/{1}/query" , environmentId , collectionId ) ) ;
0 commit comments