<commit_before><?php

namespace bbn\Appui;

use bbn\Db;
use bbn\Models\Tts\Cache;
use bbn\Models\Tts\Dbconfig;
use bbn\Mvc\Model;
use bbn\User;
use bbn\Util\Timer;
use bbn\X;
use Opis\Closure\SerializableClosure;

class Search
{
  use Dbconfig, Cache;

  /**
   * @var Db
   */
  protected Db $db;

  /**
   * @var User
   */
  protected User $user;

  /**
   * @var Model
   */
  protected Model $model;

  /**
   * @var string
   */
  protected string $cfg_cache_name = 'search_content';

  /**
   * @var string
   */
  protected string $search_cache_name = 'search_%s';

  /**
   * @var array
   */
  protected static $default_class_cfg = [
    'table' => 'bbn_search',
    'tables' => [
      'search' => 'bbn_search',
      'search_results' => 'bbn_search_results'
    ],
    'arch' => [
      'search' => [
        'id' => 'id',
        'id_user' => 'id_user',
        'value' => 'value',
        'num' => 'num',
        'last' => 'last'
      ],
      'search_results' => [
        'id' => 'id',
        'id_search' => 'id_search',
        'num' => 'num',
        'last' => 'last',
        'signature' => 'signature',
        'result' => 'result'
      ]
    ]
  ];

  /**
   * @var array|null
   */
  protected array $search_cfg = [];

  /**
   * @var Timer
   */
  protected Timer $timer;

  /**
   * Time limit in milliseconds for queries.
   *
   * @var int
   */
  protected int $time_limit = 50;

  /**
   * @var array
   */
  protected static array $functions = [];


  public function __construct(Model $model, array $cfg = [])
  {
    $this->ctrl   = $ctrl;
    // $ctrl->getCustomModelGroup('', 'appui-search'), $ctrl->data['value'], $search->get($ctrl->data['value'])
    $this->db     = Db::getInstance();
    $this->user   = User::getInstance();

    if (!$this->db) {
      throw new \Exception('Db instance cannot be found!');
    }

    if (!$this->user) {
      throw new \Exception(X::_('User is not logged in!'));
    }

    $this->_init_class_cfg($cfg);
    $this->cacheInit();
    $this->timer      = new Timer();
    $model->getCustomModelGroup('', 'appui-search');<commit_msg>Commented former use of $ctrl in Search<commit_after><?php

namespace bbn\Appui;

use bbn\Db;
use bbn\Models\Tts\Cache;
use bbn\Models\Tts\Dbconfig;
use bbn\Mvc\Model;
use bbn\User;
use bbn\Util\Timer;
use bbn\X;
use Opis\Closure\SerializableClosure;

class Search
{
  use Dbconfig, Cache;

  /**
   * @var Db
   */
  protected Db $db;

  /**
   * @var User
   */
  protected User $user;

  /**
   * @var Model
   */
  protected Model $model;

  /**
   * @var string
   */
  protected string $cfg_cache_name = 'search_content';

  /**
   * @var string
   */
  protected string $search_cache_name = 'search_%s';

  /**
   * @var array
   */
  protected static $default_class_cfg = [
    'table' => 'bbn_search',
    'tables' => [
      'search' => 'bbn_search',
      'search_results' => 'bbn_search_results'
    ],
    'arch' => [
      'search' => [
        'id' => 'id',
        'id_user' => 'id_user',
        'value' => 'value',
        'num' => 'num',
        'last' => 'last'
      ],
      'search_results' => [
        'id' => 'id',
        'id_search' => 'id_search',
        'num' => 'num',
        'last' => 'last',
        'signature' => 'signature',
        'result' => 'result'
      ]
    ]
  ];

  /**
   * @var array|null
   */
  protected array $search_cfg = [];

  /**
   * @var Timer
   */
  protected Timer $timer;

  /**
   * Time limit in milliseconds for queries.
   *
   * @var int
   */
  protected int $time_limit = 50;

  /**
   * @var array
   */
  protected static array $functions = [];


  public function __construct(Model $model, array $cfg = [])
  {
    //$this->ctrl   = $ctrl;
    // $ctrl->getCustomModelGroup('', 'appui-search'), $ctrl->data['value'], $search->get($ctrl->data['value'])
    $this->db     = Db::getInstance();
    $this->user   = User::getInstance();

    if (!$this->db) {
      throw new \Exception('Db instance cannot be found!');
    }

    if (!$this->user) {
      throw new \Exception(X::_('User is not logged in!'));
    }

    $this->_init_class_cfg($cfg);
    $this->cacheInit();
    $this->timer      = new Timer();
    $model->getCustomModelGroup('', 'appui-search');
{'fraction_non_alphanumeric': 0.1884433962264151, 'fraction_numerical': 0.0009433962264150943, 'mean_word_length': 2.279969064191802, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 65, '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': '5183461', 'n_tokens_mistral': 1534, 'n_tokens_neox': 1489, 'n_words': 321}