<commit_before><?php namespace Hook\Controllers;

use Hook\Model;
use Hook\Http\Input;

class CollectionController extends HookController {

    public function index($name) {
        $query = Model\App::collection($name)->filter(Input::get('q'));

        // Select fieds
        if ($fields = Input::get('select')) {
            $query = $query->select($fields);
        }

        // Apply ordering
        if ($s = Input::get('s')) {
            foreach ($s as $ordering) {
                $query->orderBy(reset($ordering), end($ordering));
            }
        }

        // Apply group
        if ($group = Input::get('g')) {
            foreach ($group as $field) {
                $query = $query->groupBy($field);
            }
        }<commit_msg>use _id as default sort field. fixes #61<commit_after><?php namespace Hook\Controllers;

use Hook\Model;
use Hook\Http\Input;

class CollectionController extends HookController {

    public function index($name) {
        $query = Model\App::collection($name)->filter(Input::get('q'));

        // Select fieds
        if ($fields = Input::get('select')) {
            $query = $query->select($fields);
        }

        // Apply ordering
        if ($s = Input::get('s', array(array('_id', 'asc')))) {
            foreach ($s as $ordering) {
                $query->orderBy(reset($ordering), end($ordering));
            }
        }

        // Apply group
        if ($group = Input::get('g')) {
            foreach ($group as $field) {
                $query = $query->groupBy($field);
            }
        }
{'fraction_non_alphanumeric': 0.161474888747616, 'fraction_numerical': 0.0012714558169103624, 'mean_word_length': 1.9420560747663551, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4139725', 'n_tokens_mistral': 444, 'n_tokens_neox': 426, 'n_words': 99}