    /*
     *  call-seq:
     *     Sort.new(sort_fields = [SortField::SCORE, SortField::DOC_ID], reverse = false) -> Sort
     *
     *  Create a new Sort object. If +reverse+ is true, all sort_fields will be
     *  reversed so if any of them are already reversed the  will be turned back
     *  to their natural order again. By default
     */
    static VALUE
    frb_sort_init(int argc, VALUE *argv, VALUE self)
    {
        int i;
        VALUE rfields, rreverse;
        bool reverse = false;
        bool has_sfd = false;
        GET_SORT();
        switch (rb_scan_args(argc, argv, "02", &rfields, &rreverse)) {
            case 2: reverse = RTEST(rreverse);
            case 1:
                    if (TYPE(rfields) == T_ARRAY) {
                        int i;
                        for (i = 0; i < RARRAY_LEN(rfields); i++) {
                            frb_sort_add(sort, RARRAY_PTR(rfields)[i], reverse);
                        }
                    } else {
                        frb_sort_add(sort, rfields, reverse);
                    }
                    for (i = 0; i < sort->size; i++) {
                        if (sort->sort_fields[i] == &SORT_FIELD_DOC) has_sfd = true;
                    }
                    if (!has_sfd) {
                        sort_add_sort_field(sort, (SortField *)&SORT_FIELD_DOC);
                    }
                    break;
            case 0:
                    sort_add_sort_field(sort, (SortField *)&SORT_FIELD_SCORE);
                    sort_add_sort_field(sort, (SortField *)&SORT_FIELD_DOC);
        }

        return self;
    }