@@ -2993,6 +2993,12 @@ public sealed class OperationOptions
2993
2993
/// </summary>
2994
2994
public static readonly string OP_PAGED_RESULTS_COOKIE = "PAGED_RESULTS_COOKIE" ;
2995
2995
2996
+ /// <summary>
2997
+ /// An option to use with <seealso cref="SearchApiOp"/> that specifies the policy used for calculating
2998
+ /// the total number of paged results.
2999
+ /// </summary>
3000
+ public const string OP_TOTAL_PAGED_RESULTS_POLICY = "TOTAL_PAGED_RESULTS_POLICY" ;
3001
+
2996
3002
/// <summary>
2997
3003
/// An option to use with <seealso cref="SearchApiOp"/> that specifies the index within
2998
3004
/// the result set of the first result which should be returned.
@@ -3137,6 +3143,22 @@ public string PagedResultsCookie
3137
3143
}
3138
3144
}
3139
3145
3146
+ /// <summary>
3147
+ /// Returns the <seealso cref="SearchResult.CountPolicy"/> used to calculate
3148
+ /// <seealso cref="SearchResult#getTotalPagedResults()"/>.
3149
+ /// </summary>
3150
+ /// <returns> The count policy. </returns>
3151
+ /// <seealso cref= SearchResult#getTotalPagedResults()</seealso>
3152
+ /// <remarks>Since 1.5</remarks>
3153
+ public SearchResult . CountPolicy TotalPagedResultsPolicy
3154
+ {
3155
+ get
3156
+ {
3157
+ return ( SearchResult . CountPolicy ) CollectionUtil . GetValue (
3158
+ _operationOptions , OP_TOTAL_PAGED_RESULTS_POLICY , SearchResult . CountPolicy . NONE ) ;
3159
+ }
3160
+ }
3161
+
3140
3162
/// <summary>
3141
3163
/// Returns the index within the result set of the first result which should
3142
3164
/// be returned. Paged results will be enabled if and only if the page size
@@ -3372,6 +3394,22 @@ public string PagedResultsCookie
3372
3394
}
3373
3395
}
3374
3396
3397
+ /// <summary>
3398
+ /// Sets the policy for calculating the total number of paged results. If no
3399
+ /// count policy is supplied or paged results are not requested a default of
3400
+ /// <seealso cref="SearchResult.CountPolicy#NONE"/> will be used. This will result in no count being
3401
+ /// performed and no overhead incurred.
3402
+ /// </summary>
3403
+ /// <remarks>Since 1.5</remarks>
3404
+ public SearchResult . CountPolicy TotalPagedResultsPolicy
3405
+ {
3406
+ set
3407
+ {
3408
+ Assertions . NullCheck ( value , "totalPagedResultsPolicy" ) ;
3409
+ _options [ OperationOptions . OP_TOTAL_PAGED_RESULTS_POLICY ] = value ;
3410
+ }
3411
+ }
3412
+
3375
3413
/// <summary>
3376
3414
/// Convenience method to set
3377
3415
/// <seealso cref="OperationOptions#OP_PAGED_RESULTS_OFFSET"/>
@@ -4834,15 +4872,48 @@ public ScriptContext Build()
4834
4872
public sealed class SearchResult
4835
4873
{
4836
4874
4875
+ /// <summary>
4876
+ /// An enum of count policy types.
4877
+ /// </summary>
4878
+ /// <seealso cref= OperationOptionsBuilder#setTotalPagedResultsPolicy(CountPolicy) </seealso>
4879
+ /// <seealso cref= SearchResult#getTotalPagedResultsPolicy() </seealso>
4880
+ public enum CountPolicy
4881
+ {
4882
+ /// <summary>
4883
+ /// There should be no count returned. No overhead should be incurred.
4884
+ /// </summary>
4885
+ NONE ,
4886
+
4887
+ /// <summary>
4888
+ /// Estimated count may be used. If no estimation is available it is up
4889
+ /// to the implementor whether to return an <seealso cref="#EXACT"/> count or
4890
+ /// <seealso cref="#NONE"/>. It should be known to the client which was used as in
4891
+ /// <seealso cref="SearchResult#getTotalPagedResultsPolicy()"/>
4892
+ /// </summary>
4893
+ ESTIMATE ,
4894
+
4895
+ /// <summary>
4896
+ /// Exact count is required.
4897
+ /// </summary>
4898
+ EXACT
4899
+ }
4900
+
4901
+ /// <summary>
4902
+ /// The value provided when no count is known or can reasonably be supplied.
4903
+ /// </summary>
4904
+ public const int NoCount = - 1 ;
4905
+
4837
4906
private readonly string _pagedResultsCookie ;
4907
+ private readonly CountPolicy _totalPagedResultsPolicy ;
4908
+ private readonly int _totalPagedResults ;
4838
4909
private readonly int _remainingPagedResults ;
4839
4910
4840
4911
/// <summary>
4841
4912
/// Creates a new search result with a {@code null} paged results cookie and
4842
4913
/// no estimate of the total number of remaining results.
4843
4914
/// </summary>
4844
4915
public SearchResult ( )
4845
- : this ( null , - 1 )
4916
+ : this ( null , CountPolicy . NONE , NoCount , NoCount )
4846
4917
{
4847
4918
}
4848
4919
@@ -4860,9 +4931,41 @@ public SearchResult()
4860
4931
/// {@code -1} if paged results were not requested, or if the
4861
4932
/// total number of remaining results is unknown. </param>
4862
4933
public SearchResult ( string pagedResultsCookie , int remainingPagedResults )
4934
+ : this ( pagedResultsCookie , CountPolicy . NONE , NoCount , remainingPagedResults )
4863
4935
{
4864
- this . _pagedResultsCookie = pagedResultsCookie ;
4865
- this . _remainingPagedResults = remainingPagedResults ;
4936
+ }
4937
+
4938
+ /// <summary>
4939
+ /// Creates a new query response with the provided paged results cookie and a
4940
+ /// count of the total number of resources according to
4941
+ /// <seealso cref="#totalPagedResultsPolicy"/>.
4942
+ /// </summary>
4943
+ /// <param name="pagedResultsCookie">
4944
+ /// The opaque cookie which should be used with the next paged
4945
+ /// results query request, or {@code null} if paged results were
4946
+ /// not requested, or if there are not more pages to be returned. </param>
4947
+ /// <param name="totalPagedResultsPolicy">
4948
+ /// The policy that was used to calculate
4949
+ /// <seealso cref="#totalPagedResults"/>. If none is specified ({@code null}
4950
+ /// ), then <seealso cref="CountPolicy#NONE"/> is assumed. </param>
4951
+ /// <param name="totalPagedResults">
4952
+ /// The total number of paged results requested in adherence to
4953
+ /// the <seealso cref="OperationOptions#getTotalPagedResultsPolicy()"/> in
4954
+ /// the request, or <seealso cref="#NO_COUNT"/> if paged results were not
4955
+ /// requested, the count policy is {@code NONE}, or if the total
4956
+ /// number of results is unknown. </param>
4957
+ /// <param name="remainingPagedResults">
4958
+ /// An estimate of the total number of remaining results to be
4959
+ /// returned in subsequent paged results query requests, or
4960
+ /// {@code -1} if paged results were not requested, or if the
4961
+ /// total number of remaining results is unknown.</param>
4962
+ /// <remarks>Since 1.5</remarks>
4963
+ public SearchResult ( string pagedResultsCookie , CountPolicy totalPagedResultsPolicy , int totalPagedResults , int remainingPagedResults )
4964
+ {
4965
+ _pagedResultsCookie = pagedResultsCookie ;
4966
+ _totalPagedResultsPolicy = totalPagedResultsPolicy ;
4967
+ _totalPagedResults = totalPagedResults ;
4968
+ _remainingPagedResults = remainingPagedResults ;
4866
4969
}
4867
4970
4868
4971
/// <summary>
@@ -4880,6 +4983,39 @@ public string PagedResultsCookie
4880
4983
}
4881
4984
}
4882
4985
4986
+ /// <summary>
4987
+ /// Returns the policy that was used to calculate the
4988
+ /// {@literal totalPagedResults}.
4989
+ /// </summary>
4990
+ /// <returns> The count policy. </returns></seealso>
4991
+ /// <remarks>Since 1.5</remarks>
4992
+ public CountPolicy TotalPagedResultsPolicy
4993
+ {
4994
+ get
4995
+ {
4996
+ return _totalPagedResultsPolicy ;
4997
+ }
4998
+ }
4999
+
5000
+ /// <summary>
5001
+ /// Returns the total number of paged results in adherence with the
5002
+ /// <seealso cref="OperationOptions#getTotalPagedResultsPolicy()"/> in the request or
5003
+ /// <seealso cref="#NO_COUNT"/> if paged results were not requested, the count policy
5004
+ /// is {@code NONE}, or the total number of paged results is unknown.
5005
+ /// </summary>
5006
+ /// <returns> A count of the total number of paged results to be returned in
5007
+ /// subsequent paged results query requests, or <seealso cref="#NO_COUNT"/> if
5008
+ /// paged results were not requested, or if the total number of paged
5009
+ /// results is unknown. </returns>
5010
+ /// <remarks>Since 1.5</remarks>
5011
+ public int TotalPagedResults
5012
+ {
5013
+ get
5014
+ {
5015
+ return _totalPagedResults ;
5016
+ }
5017
+ }
5018
+
4883
5019
/// <summary>
4884
5020
/// Returns an estimate of the total number of remaining results to be
4885
5021
/// returned in subsequent paged results search requests.
0 commit comments