<commit_before><?php

namespace SilverStripe\FullTextSearch\Search\Variants;

use SilverStripe\ORM\DataObject;
use SilverStripe\Core\ClassInfo;
use SilverStripe\FullTextSearch\Search\SearchIntrospection;
use SilverStripe\Versioned\Versioned;
use SilverStripe\FullTextSearch\Search\Queries\SearchQuery;

class SearchVariantVersioned extends SearchVariant
{
    public function appliesTo($class, $includeSubclasses)
    {
        return SearchIntrospection::has_extension($class, Versioned::class, $includeSubclasses);
    }

    public function currentState()
    {
        return Versioned::get_stage();
    }
    public function reindexStates()
    {
        return array('Stage', 'Live');
    }
    public function activateState($state)
    {
        Versioned::set_stage($state);
    }

    public function alterDefinition($class, $index)
    {
        $self = get_class($this);

        $this->addFilterField($index, '_versionedstage', array(
            'name' => '_versionedstage',
            'field' => '_versionedstage',
            'fullfield' => '_versionedstage',
            'base' => DataObject::getSchema()->baseDataClass($class),
            'origin' => $class,
            'type' => 'String',
            'lookup_chain' => array(array('call' => 'variant', 'variant' => $self, 'method' => 'currentState'))
        ));
    }

    public function alterQuery($query, $index)
    {
        $stage = $this->currentState();
        $query->filter('_versionedstage', array($stage, SearchQuery::$missing));
    }

    public function extractManipulationState(&$manipulation)
    {
        $self = get_class($this);

        foreach ($manipulation as $table => $details) {
            $class = $details['class'];
            $stage = 'Stage';

            if (preg_match('/^(.*)_Live$/', $table, $matches)) {
                $class = $matches[1];
                $stage = 'Live';
            }

            if (ClassInfo::exists($class) && $this->appliesTo($class, false)) {
                $manipulation[$table]['class'] = $class;
                $manipulation[$table]['state'][$self] = $stage;
            }
        }
    }

    public function extractStates(&$table, &$ids, &$fields)
    {
        $class = $table;
        $suffix = null;


        if (ClassInfo::exists($class) && $this->appliesTo($class, false)) {
            $table = $class;
            $self = get_class($this);

            foreach ($ids as $i => $statefulid) {
                $ids[$i]['state'][$self] = $suffix ? $suffix : 'Stage';
            }
        }
    }
}
<commit_msg>Use actual classname in SearchVariantVersioned<commit_after><?php

namespace SilverStripe\FullTextSearch\Search\Variants;

use SilverStripe\ORM\DataObject;
use SilverStripe\Core\ClassInfo;
use SilverStripe\FullTextSearch\Search\SearchIntrospection;
use SilverStripe\Versioned\Versioned;
use SilverStripe\FullTextSearch\Search\Queries\SearchQuery;

class SearchVariantVersioned extends SearchVariant
{
    public function appliesTo($class, $includeSubclasses)
    {
        return SearchIntrospection::has_extension($class, Versioned::class, $includeSubclasses);
    }

    public function currentState()
    {
        return Versioned::get_stage();
    }
    public function reindexStates()
    {
        return array('Stage', 'Live');
    }
    public function activateState($state)
    {
        Versioned::set_stage($state);
    }

    public function alterDefinition($class, $index)
    {
        $self = get_class($this);

        $this->addFilterField($index, '_versionedstage', array(
            'name' => '_versionedstage',
            'field' => '_versionedstage',
            'fullfield' => '_versionedstage',
            'base' => DataObject::getSchema()->baseDataClass($class),
            'origin' => $class,
            'type' => 'String',
            'lookup_chain' => array(array('call' => 'variant', 'variant' => $self, 'method' => 'currentState'))
        ));
    }

    public function alterQuery($query, $index)
    {
        $stage = $this->currentState();
        $query->filter('_versionedstage', array($stage, SearchQuery::$missing));
    }

    public function extractManipulationState(&$manipulation)
    {
        $self = get_class($this);

        foreach ($manipulation as $table => $details) {
            $class = $details['class'];
            $stage = 'Stage';

            if (preg_match('/^(.*)_Live$/', $table, $matches)) {
                $class = DataObject::getSchema()->tableClass($matches[1]);
                $stage = 'Live';
            }

            if (ClassInfo::exists($class) && $this->appliesTo($class, false)) {
                $manipulation[$table]['class'] = $class;
                $manipulation[$table]['state'][$self] = $stage;
            }
        }
    }

    public function extractStates(&$table, &$ids, &$fields)
    {
        $class = $table;
        $suffix = null;


        if (ClassInfo::exists($class) && $this->appliesTo($class, false)) {
            $table = $class;
            $self = get_class($this);

            foreach ($ids as $i => $statefulid) {
                $ids[$i]['state'][$self] = $suffix ? $suffix : 'Stage';
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.15331278890600925, 'fraction_numerical': 0.0003852080123266564, 'mean_word_length': 2.494616419919246, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 40, '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': '1683318', 'n_tokens_mistral': 1527, 'n_tokens_neox': 1482, 'n_words': 270}