Skip to content

Commit 5ef9485

Browse files
authored
Merge pull request #4784 from KoenZomers/Issue4758
Fixes `-RetryCount` parameter being ignored with `Submit-PnPSearchQuery`
2 parents f46e67d + ad94ecf commit 5ef9485

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
113113
- Fixed passing a `Get-PnPRecycleBinItem` result or a GUID to `Restore-PnPRecycleBinItem` not working correctly. [#4667](https://github.com/pnp/powershell/pull/4667)
114114
- Fixed `Get-PnPChangeLog` not returning the changelog [#4707](https://github.com/pnp/powershell/pull/4707)
115115
- Fixed `-Description` and `-Sequence` not being applied when providing these through `Add-PnPApplicationCustomizer` [#4767](https://github.com/pnp/powershell/pull/4767)
116+
- Fixed `-RetryCount` parameter being ignored with `Submit-PnPSearchQuery` [#4784](https://github.com/pnp/powershell/pull/4784)
116117

117118
### Removed
118119

src/Commands/Search/SubmitSearchQuery.cs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -117,26 +117,26 @@ internal IEnumerable<object> Run()
117117
PnPResultTableCollection finalResults = null;
118118
do
119119
{
120-
KeywordQuery keywordQuery = CreateKeywordQuery(clientFunction);
121-
keywordQuery.StartRow = startRow;
122-
keywordQuery.RowLimit = rowLimit;
123-
124-
if (All.IsPresent)
125-
{
126-
if (currentCount != 0)
127-
{
128-
keywordQuery.Refiners = null; // Only need to set on first page for auto paging
129-
}
130-
keywordQuery.StartRow = 0;
131-
keywordQuery.QueryText += " IndexDocId>" + lastDocId;
132-
}
120+
var searchExec = new SearchExecutor(ClientContext);
133121

134122
// We'll always try at least once, even if RetryCount is 0 (default)
135123
for (var iterator = 0; iterator <= RetryCount; iterator++)
136124
{
137125
try
138126
{
139-
var searchExec = new SearchExecutor(ClientContext);
127+
KeywordQuery keywordQuery = CreateKeywordQuery(clientFunction);
128+
keywordQuery.StartRow = startRow;
129+
keywordQuery.RowLimit = rowLimit;
130+
131+
if (All.IsPresent)
132+
{
133+
if (currentCount != 0)
134+
{
135+
keywordQuery.Refiners = null; // Only need to set on first page for auto paging
136+
}
137+
keywordQuery.StartRow = 0;
138+
keywordQuery.QueryText += " IndexDocId>" + lastDocId;
139+
}
140140
var results = searchExec.ExecuteQuery(keywordQuery);
141141
ClientContext.ExecuteQueryRetry();
142142

@@ -190,15 +190,20 @@ internal IEnumerable<object> Run()
190190
// If we're not retrying, or if we're on the last retry, don't catch the exception
191191
catch (Exception ex)
192192
{
193-
if (RetryCount > 0 && iterator < RetryCount)
193+
if (RetryCount > 0 && iterator < (RetryCount - 1))
194194
{
195195
var waitTime = 5 * (iterator + 1);
196196

197-
WriteVerbose($"Search operation failed with exception {ex.Message}. Attempt {iterator + 1} out of {RetryCount}. Retrying in {waitTime} seconds.");
197+
WriteVerbose($"Search operation failed with exception {ex.Message.TrimEnd('.')}. Attempt {iterator + 1} out of {RetryCount}. Retrying in {waitTime} seconds.");
198198

199199
Thread.Sleep(TimeSpan.FromSeconds(waitTime));
200200
continue;
201201
}
202+
else if (iterator == RetryCount - 1)
203+
{
204+
WriteVerbose($"Search operation failed with exception {ex.Message.TrimEnd('.')}. Attempt {iterator + 1} out of {RetryCount}. Done retrying.");
205+
continue;
206+
}
202207
else
203208
{
204209
throw;

0 commit comments

Comments
 (0)