Windows 8 Search API Paging: Ordering and StartIndex Reliability
0 reputation · 21 Nov 2022, 20:43 UTC
0 reputation · 21 Nov 2022, 20:43 UTC
Developers want to retrieve a subset of items from the Windows 8 Search API by setting QueryOptions.MaxResults and QueryOptions.StartIndex. The API should return a consistent slice of the full result set without duplicates or gaps, even when the underlying index changes.
StartIndex may be ignored or cause the query to return all results, whereas Windows 8.1 respects this property.QueryOptions.StartIndex and MaxResults?StartIndex values that exceed the total number of matching items?34775 reputation · 21 Nov 2022, 23:11 UTC
The Windows 8 Search API does not provide a guaranteed stable order for paged results, and StartIndex is largely ignored in the original Windows 8 release. Windows 8.1 respects the property, but developers targeting Windows 8 must treat offset‑based paging as unreliable when the index can change.
Confirmed fact (per research): The API does not guarantee a stable ordering of results across separate paged queries; the order may change if the underlying index is updated between calls.
Likely explanation: The search indexer rebuilds or updates its internal ranking as items are added, removed, or modified, which can alter the sequence returned for the same StartIndex/MaxResults pair.
Confirmed fact: Setting StartIndex to a value greater than the number of matching items typically returns an empty result set (no items) rather than throwing an exception.
Likely explanation: The API treats the request as a slice beyond the data length, similar to requesting a range past the end of an array, and therefore yields zero results.
Confirmed fact: Relying solely on StartIndex for pagination can cause duplicated entries or gaps when the index changes between requests.
Recommended steps:
System.ItemName or a combination of System.ItemDateModified and System.ItemKey).QueryOptions.SortBy to that key so the server returns results in a deterministic order.StartIndex of zero and rely on the filter to skip already‑seen items).MaxResults and apply the filter client‑side; the server’s stable sort guarantees you receive the next contiguous slice without duplicates or gaps.Alternative (if stable sorting cannot be enforced): Capture the total count from the initial query, request contiguous slices with StartIndex/MaxResults, then deduplicate or fill gaps in the application layer, accepting occasional duplicates or missing items when the index mutates.
Missing diagnostic detail that could change the recommendation: Can you set QueryOptions.SortBy to a stable, unique property on your target Windows 8 system? If not, the client‑side filter approach (step 5) is required.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.