Search and Sync Improvement

Common Pagination Options

The Search will be able to utilise four new OperationOptions.

Operation Options
    /**
     * An option to use with {@link SearchApiOp} that specifies an opaque cookie
     * which is used by the connector to track its position in the set of query
     * results.
     */
    public static final String OP_PAGED_RESULTS_COOKIE = "PAGED_RESULTS_COOKIE";
    /**
     * An option to use with {@link SearchApiOp} that specifies the index within
     * the result set of the first result which should be returned.
     */
    public static final String OP_PAGED_RESULTS_OFFSET = "PAGED_RESULTS_OFFSET";
    /**
     * An option to use with {@link SearchApiOp} that specifies the requested
     * page results page size.
     */
    public static final String OP_PAGE_SIZE = "PAGE_SIZE";
    /**
     * An option to use with {@link SearchApiOp} that specifies the sort keys
     * which should be used for ordering the {@link ConnectorObject} returned by
     * this search request.
     */
    public static final String OP_SORT_KEYS = "SORT_KEYS";

 

Search Operation can return with SearchResult

The final result of a query request returned after all connector objects matching the request have been returned. In addition to indicating that no more objects are to be returned by the search, the search result will contain page results state information if result paging has been enabled for the search.

Paged Search Implementation
        String cookie = options.getPagedResultsCookie();
        for (int i = 0; i < 100; i++ ) {
            handler.handle(results[i]);
        }
        if (handler instanceof SearchResultsHandler) {
            ((SearchResultsHandler)handler).handleResult(new SearchResult(cookie, 100)); 
        }

 

Sync Operation can return with the latest SyncToken

The operation should return with the latest sync token even if there is no change to avoid to iterate over and over again the irrelevant changes.

Sync Implementation
        for (SyncDelta delta: Collections.<SyncDelta>emptyList()) {
            handler.handle(delta);
        }
        if (handler instanceof SyncTokenResultsHandler) {
            ((SyncTokenResultsHandler)handler).handleResult(lastToken);
        }