Sort the query string by offset, maintaining offset to data correlations.

This method MUST retain the state of the current instance, and return
an instance that contains the modified query

@see https://url.spec.whatwg.org/#dom-urlsearchparams-sort
483120
public function sort(): self
    {
        if (count($this->pairs) === count(array_count_values(array_column($this->pairs, 0)))) {
            return $this;
        }

        $pairs = array_merge(...array_values(array_reduce($this->pairs, [$this, 'reducePairs'], [])));
        if ($pairs === $this->pairs) {
            return $this;
        }

        $clone = clone $this;
        $clone->pairs = $pairs;

        return $clone;
    }
927557
public final List<T> findSortedByQuery(String query, String sort, Object... params) {
        return this.findSortedByQuery(query, sort, (Integer) null, (Integer) null, params);
    }
1051959
static String updateQueryWithArrayParameters(String parsedQuery, List<ArrayParameter> arrayParametersSortedAsc) {
        if(arrayParametersSortedAsc.isEmpty()) {
            return parsedQuery;
        }

        StringBuilder sb = new StringBuilder();

        Iterator<ArrayParameter> parameterToReplaceIt = arrayParametersSortedAsc.iterator();
        ArrayParameter nextParameterToReplace = parameterToReplaceIt.next();
        // PreparedStatement index starts at 1
        int currentIndex = 1;
        for(char c : parsedQuery.toCharArray()) {
            if(nextParameterToReplace != null && c == '?') {
                if(currentIndex == nextParameterToReplace.parameterIndex) {
                    sb.append("?");
                    for(int i = 1; i < nextParameterToReplace.parameterCount; i++) {
                        sb.append(",?");
                    }

                    if(parameterToReplaceIt.hasNext()) {
                        nextParameterToReplace = parameterToReplaceIt.next();
                    } else {
                        nextParameterToReplace = null;
                    }
                } else {
                    sb.append(c);
                }
                currentIndex++;
            } else {
                sb.append(c);
            }
        }

        return sb.toString();
    }
1002789
function queryFunction(query) {
    var term = query.term;
    var offset = query.offset || 0;
    var results = cities.filter(function(city) {
        return transformText(city).indexOf(transformText(term)) > -1;
    });
    results.sort(function(a, b) {
        a = transformText(a);
        b = transformText(b);
        var startA = (a.slice(0, term.length) === term),
            startB = (b.slice(0, term.length) === term);
        if (startA) {
            return (startB ? (a > b ? 1 : -1) : -1);
        } else {
            return (startB ? 1 : (a > b ? 1 : -1));
        }
    });
    setTimeout(query.callback({
        more: results.length > offset + 10,
        results: results.slice(offset, offset + 10)
    }), 500);
}
1052020
public static void sortBy(MutableFst fst, Comparator<Arc> comparator) {
    int numStates = fst.getStateCount();
    for (int i = 0; i < numStates; i++) {
      MutableState s = fst.getState(i);
      s.arcSort(comparator);
    }
  }
658927
function (query) {
            if (query instanceof Query && query.query.sort) {
                if (this.$.query) {
                    query.query.where = this.$.query.query.where;
                }


                var options = _.defaults({}, {
                    query: query,
                    root: this.getRoot()
                }, this.$);

                var sortCacheId = query.sortCacheId();

                if (!this.$sortCache[sortCacheId]) {
                    this.$sortCache[sortCacheId] = this._createSortedCollection(query, options);
                }

                return this.$sortCache[sortCacheId];
            }

            return this;
        }
1132474
protected String getSortOrderStringForQuery(MatcherPattern target, QueryParameters parameter) {
        String result = "";
        if (parameter.getSortOrder() != null && parameter.getSortOrder().length() >= 1) {
            result = parameter.getSortOrder();
        } else {
            result = target.getTableInfo().getDefaultSortOrderString();
        }
        return result;
    }
274680
private void orderResults(ResultSet cqlRows) throws InvalidRequestException
    {
        if (cqlRows.size() == 0 || !needsPostQueryOrdering())
            return;

        assert orderingIndexes != null;

        List<Integer> idToSort = new ArrayList<Integer>();
        List<Comparator<ByteBuffer>> sorters = new ArrayList<Comparator<ByteBuffer>>();

        for (ColumnIdentifier.Raw identifier : parameters.orderings.keySet())
        {
            ColumnDefinition orderingColumn = cfm.getColumnDefinition(identifier.prepare(cfm));
            idToSort.add(orderingIndexes.get(orderingColumn.name));
            sorters.add(orderingColumn.type);
        }

        Comparator<List<ByteBuffer>> comparator = idToSort.size() == 1
                                                ? new SingleColumnComparator(idToSort.get(0), sorters.get(0))
                                                : new CompositeComparator(sorters, idToSort);
        Collections.sort(cqlRows.rows, comparator);
    }
240726
private void parse(State state, final String uri, final int offset, final int end) {
        boolean encoded = false;
        int mark = offset;
        int path_mark = 0;

        for (int i = offset; i < end; i++) {
            char c = uri.charAt(i);

            switch (state) {
                case START: {
                    switch (c) {
                        case '/':
                            mark = i;
                            state = State.HOST_OR_PATH;
                            break;
                        case ';':
                            mark = i + 1;
                            state = State.PARAM;
                            break;
                        case '?':
                            // assume empty path (if seen at start)
                            _path = "";
                            mark = i + 1;
                            state = State.QUERY;
                            break;
                        case '#':
                            mark = i + 1;
                            state = State.FRAGMENT;
                            break;
                        case '*':
                            _path = "*";
                            state = State.ASTERISK;
                            break;

                        default:
                            mark = i;
                            if (_scheme == null)
                                state = State.SCHEME_OR_PATH;
                            else {
                                path_mark = i;
                                state = State.PATH;
                            }
                    }

                    continue;
                }

                case SCHEME_OR_PATH: {
                    switch (c) {
                        case ':':
                            // must have been a scheme
                            _scheme = uri.substring(mark, i);
                            // Start again with scheme set
                            state = State.START;
                            break;

                        case '/':
                            // must have been in a path and still are
                            state = State.PATH;
                            break;

                        case ';':
                            // must have been in a path
                            mark = i + 1;
                            state = State.PARAM;
                            break;

                        case '?':
                            // must have been in a path
                            _path = uri.substring(mark, i);
                            mark = i + 1;
                            state = State.QUERY;
                            break;

                        case '%':
                            // must have be in an encoded path
                            encoded = true;
                            state = State.PATH;
                            break;

                        case '#':
                            // must have been in a path
                            _path = uri.substring(mark, i);
                            state = State.FRAGMENT;
                            break;
                    }
                    continue;
                }

                case HOST_OR_PATH: {
                    switch (c) {
                        case '/':
                            _host = "";
                            mark = i + 1;
                            state = State.HOST;
                            break;

                        case '@':
                        case ';':
                        case '?':
                        case '#':
                            // was a path, look again
                            i--;
                            path_mark = mark;
                            state = State.PATH;
                            break;
                        default:
                            // it is a path
                            path_mark = mark;
                            state = State.PATH;
                    }
                    continue;
                }

                case HOST: {
                    switch (c) {
                        case '/':
                            _host = uri.substring(mark, i);
                            path_mark = mark = i;
                            state = State.PATH;
                            break;
                        case ':':
                            if (i > mark)
                                _host = uri.substring(mark, i);
                            mark = i + 1;
                            state = State.PORT;
                            break;
                        case '@':
                            if (_user != null)
                                throw new IllegalArgumentException("Bad authority");
                            _user = uri.substring(mark, i);
                            mark = i + 1;
                            break;

                        case '[':
                            state = State.IPV6;
                            break;
                    }
                    continue;
                }

                case IPV6: {
                    switch (c) {
                        case '/':
                            throw new IllegalArgumentException("No closing ']' for ipv6 in " + uri);
                        case ']':
                            c = uri.charAt(++i);
                            _host = uri.substring(mark, i);
                            if (c == ':') {
                                mark = i + 1;
                                state = State.PORT;
                            } else {
                                path_mark = mark = i;
                                state = State.PATH;
                            }
                            break;
                    }

                    continue;
                }

                case PORT: {
                    if (c == '@') {
                        if (_user != null)
                            throw new IllegalArgumentException("Bad authority");
                        // It wasn't a port, but a password!
                        _user = _host + ":" + uri.substring(mark, i);
                        mark = i + 1;
                        state = State.HOST;
                    } else if (c == '/') {
                        _port = TypeUtils.parseInt(uri, mark, i - mark, 10);
                        path_mark = mark = i;
                        state = State.PATH;
                    }
                    continue;
                }

                case PATH: {
                    switch (c) {
                        case ';':
                            mark = i + 1;
                            state = State.PARAM;
                            break;
                        case '?':
                            _path = uri.substring(path_mark, i);
                            mark = i + 1;
                            state = State.QUERY;
                            break;
                        case '#':
                            _path = uri.substring(path_mark, i);
                            mark = i + 1;
                            state = State.FRAGMENT;
                            break;
                        case '%':
                            encoded = true;
                            break;
                    }
                    continue;
                }

                case PARAM: {
                    switch (c) {
                        case '?':
                            _path = uri.substring(path_mark, i);
                            _param = uri.substring(mark, i);
                            mark = i + 1;
                            state = State.QUERY;
                            break;
                        case '#':
                            _path = uri.substring(path_mark, i);
                            _param = uri.substring(mark, i);
                            mark = i + 1;
                            state = State.FRAGMENT;
                            break;
                        case '/':
                            encoded = true;
                            // ignore internal params
                            state = State.PATH;
                            break;
                        case ';':
                            // multiple parameters
                            mark = i + 1;
                            break;
                    }
                    continue;
                }

                case QUERY: {
                    if (c == '#') {
                        _query = uri.substring(mark, i);
                        mark = i + 1;
                        state = State.FRAGMENT;
                    }
                    continue;
                }

                case ASTERISK: {
                    throw new IllegalArgumentException("Bad character '*'");
                }

                case FRAGMENT: {
                    _fragment = uri.substring(mark, end);
                    i = end;
                }
            }
        }


        switch (state) {
            case START:
                break;
            case SCHEME_OR_PATH:
                _path = uri.substring(mark, end);
                break;

            case HOST_OR_PATH:
                _path = uri.substring(mark, end);
                break;

            case HOST:
                if (end > mark)
                    _host = uri.substring(mark, end);
                break;

            case IPV6:
                throw new IllegalArgumentException("No closing ']' for ipv6 in " + uri);

            case PORT:
                _port = TypeUtils.parseInt(uri, mark, end - mark, 10);
                break;

            case ASTERISK:
                break;

            case FRAGMENT:
                _fragment = uri.substring(mark, end);
                break;

            case PARAM:
                _path = uri.substring(path_mark, end);
                _param = uri.substring(mark, end);
                break;

            case PATH:
                _path = uri.substring(path_mark, end);
                break;

            case QUERY:
                _query = uri.substring(mark, end);
                break;
        }

        if (!encoded) {
            if (_param == null)
                _decodedPath = _path;
            else
                _decodedPath = _path.substring(0, _path.length() - _param.length() - 1);
        }
    }
83024
public SortingParams nosort() {
    params.add(BY.raw);
    params.add(NOSORT.raw);
    return this;
  }
113299
def query(self, constraint, sortby=None, typenames=None, maxrecords=10, startposition=0):
        

        # run the raw query and get total
        # we want to exclude layers which are not valid, as it is done in the search engine
        if 'where' in constraint:  # GetRecords with constraint
            query = self._get_repo_filter(Layer.objects).filter(
                is_valid=True).extra(where=[constraint['where']], params=constraint['values'])
        else:  # GetRecords sans constraint
            query = self._get_repo_filter(Layer.objects).filter(is_valid=True)

        total = query.count()

        # apply sorting, limit and offset
        if sortby is not None:
            if 'spatial' in sortby and sortby['spatial']:  # spatial sort
                desc = False
                if sortby['order'] == 'DESC':
                    desc = True
                query = query.all()
                return [str(total),
                        sorted(query,
                               key=lambda x: float(util.get_geometry_area(getattr(x, sortby['propertyname']))),
                               reverse=desc,
                               )[startposition:startposition+int(maxrecords)]]
            else:
                if sortby['order'] == 'DESC':
                    pname = '-%s' % sortby['propertyname']
                else:
                    pname = sortby['propertyname']
                return [str(total),
                        query.order_by(pname)[startposition:startposition+int(maxrecords)]]
        else:  # no sort
            return [str(total), query.all()[startposition:startposition+int(maxrecords)]]
9614
public UrlSearchResult next() {
		if(cachedNext == null) {
			throw new NoSuchElementException("use hasNext!");
		}
		UrlSearchResult tmp = cachedNext;
		cachedNext = null;
		return tmp;
	}
528585
def sort(self, **kwargs):
        
        query = {}
        for field in kwargs:
            query[field] = kwargs[field]
        self._q.append({'$sort': query})
        return self
132194
public Long getOffset() {
    String offsetFromRequest =
        uriInfo.getQueryParameters().getFirst(OffsetParameter.getDefaultOffsetFieldName());

    return offsetFromRequest != null ? new OffsetParameter(offsetFromRequest).getValue()
        : OffsetParameter.getDefaultOffset();
  }
219695
protected final List<T> searchSorted(String searchString, String sort) {
        return this.dataAccess.searchSorted(searchString, sort);
    }
192603
public Map<String, String> getSortParameter() {

        return new HashMap<String, String>() {{
            put(sortUrlParameterName, getFields());
        }};
    }
976186
def offset(self, value):
        

        self._query = self._query.skip(value)

        return self