<commit_before><?php

namespace App\Http\Middleware;

use Closure;

class DecodeParams
{
    /**
     * WEB-979: This middleware is a work-around for `http_build_query` and its many
     * quirks. You can pass any API params as a JSON string via the `params` param.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $params = $request->get('params');

        if (isset($params)) {
            $params = json_decode($params, true);

            if (json_last_error() === JSON_ERROR_NONE) {
                $request->merge($params);
            }
        }

        return $next($request);
    }
}<commit_msg>Fix `params` for `msearch` [WEB-979]<commit_after><?php

namespace App\Http\Middleware;

use Symfony\Component\HttpFoundation\ParameterBag;
use Closure;

class DecodeParams
{
    /**
     * WEB-979: This middleware is a work-around for `http_build_query` and its many
     * quirks. You can pass any API params as a JSON string via the `params` param.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $params = $request->get('params');

        if (isset($params)) {
            $params = json_decode($params, true);

            if (json_last_error() === JSON_ERROR_NONE) {
                $request->merge($params);
            }

            // Prevents issues with `msearch`, which expects array as root item
            $request->query = new ParameterBag($request->except(['params']));
        }

        return $next($request);
    }
}
{'fraction_non_alphanumeric': 0.1259475218658892, 'fraction_numerical': 0.0052478134110787176, 'mean_word_length': 2.2561669829222013, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '2347227', 'n_tokens_mistral': 526, 'n_tokens_neox': 511, 'n_words': 137}