<commit_before><?php

namespace Metrique\Index\Traits;

trait IndexArrayTrait
{
    public function createNestedIndex(array $index, array $options = [])
    {
        $defaults = [
            'active_key' => 'active',
            'parent_key' => 'indices_id',
            'child_key' => 'children',
            'slug' => null
        ];

        $options = array_intersect_key($options, $defaults);
        $options = array_merge($defaults, $options);

        $indexMap = [];
        $nested = [];

        // Create index map & init children array.
        foreach($index as $key => $value)
        {
            // Map the database Id to the array Id
            $indexMap[$value['id']] = $key;

            // Initialise children.
            $index[$key][$options['child_key']] = [];

            // Initialise active.
            $index[$key][$options['active_key']] = false;

            // Initialise params.
            if( ! is_null($index[$key]['params']))
            {
                $index[$key]['params'] = json_decode($index[$key]['params'], true);
            }

            // Mark as active
            if( ! is_null($options['slug']))
            {
                $index[$key][$options['active_key']] = ($options['slug'] == $index[$key]['slug']) ? true : false;
            }
        }

        // Nest index
        foreach($index as $key => $value)
        {
            $indicesId = $index[$key][$options['parent_key']];
            
            // Add any root items to the nested array.
            if(is_null($indicesId))
            {<commit_msg>Add active scanning by default, for pages not entered into the index<commit_after><?php

namespace Metrique\Index\Traits;

trait IndexArrayTrait
{
    public function createNestedIndex(array $index, array $options = [])
    {
        $activeScan = true;

        $defaults = [
            'active_key' => 'active',
            'active_scan' => true,
            'parent_key' => 'indices_id',
            'child_key' => 'children',
            'slug' => null,
        ];

        $options = array_intersect_key($options, $defaults);
        $options = array_merge($defaults, $options);

        $indexMap = [];
        $nested = [];

        // Create index map & init children array.
        foreach($index as $key => $value)
        {
            // Map the database Id to the array Id
            $indexMap[$value['id']] = $key;

            // Initialise children.
            $index[$key][$options['child_key']] = [];

            // Initialise active.
            $index[$key][$options['active_key']] = false;

            // Initialise params.
            if( ! is_null($index[$key]['params']))
            {
                $index[$key]['params'] = json_decode($index[$key]['params'], true);
            }

            // Mark as active
            if( ! is_null($options['slug']))
            {
                $active = ($options['slug'] == $index[$key]['slug']) ? true : false;
                $index[$key][$options['active_key']] = $active;

                // Catch if we need to perform an active scan.
                if($active) {
                    $activeScan = false;
                }
            }
        }

        // Active Scan - if no slug is marked as active, we scan the first section of the slug.
        if( ! is_null($options['slug']))
        {
            $slug = explode('_', $options['slug'], 2);
            
            foreach($index as $key => $value)
            {
                $active = ($slug[0] == $index[$key]['slug']) ? true : false;
                $index[$key][$options['active_key']] = $active;
            }
        }

        // Nest index
        foreach($index as $key => $value)
        {
            $indicesId = $index[$key][$options['parent_key']];
            
            // Add any root items to the nested array.
            if(is_null($indicesId))
            {
{'fraction_non_alphanumeric': 0.1545757498077416, 'fraction_numerical': 0.0005126890540886952, 'mean_word_length': 1.5944148936170213, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '4714850', 'n_tokens_mistral': 1081, 'n_tokens_neox': 1060, 'n_words': 241}