<commit_before><?php
require_once dirname(__FILE__) . '/../../../bootstrap.php';

class Elastica_Query_CustomScoreTest extends PHPUnit_Framework_TestCase
{
    public function testCustomScoreQuery()
    {
        $query = new Elastica_Query_MatchAll();

        $customScoreQuery = new Elastica_Query_CustomScore();
        $customScoreQuery->setQuery($query);
        $customScoreQuery->setScript("doc['hits'].value * (param1 + param2)");
        $customScoreQuery->addParams(array('param1' => 1123, 'param2' => 2001));

        $expected = array(
            'custom_score' => array(
                'query' => array(
                    'match_all' => new stdClass,
                ),
                'script' => "doc['hits'].value * (param1 + param2)",
                'params' => array(
                    'param1' => 1123,
                    'param2' => 2001,
                )
            )
        );

        $this->assertEquals($expected, $customScoreQuery->toArray());
    }

    public function testSetScript()
    {
        $string = '_score * 2.0';
        $lang = 'mvel';
        $params = array(
            'param1' => 'one',
            'param2' => 1,
        );
        $script = new Elastica_Script($string);
        $script->setLang('mvel');
        $script->setParams($params);

        $customScoreQuery = new Elastica_Query_CustomScore();
        $customScoreQuery->setScript($script);

        $expected = array(
            'custom_score' => array(
                'query' => array(
                    'match_all' => new stdClass,
                ),
                'script' => $string,
                'params' => $params,
                'lang' => $lang,
            )
        );

        $this->assertEquals($expected, $customScoreQuery->toArray());
    }
}<commit_msg>Added constructor test for CustomScore query<commit_after><?php
require_once dirname(__FILE__) . '/../../../bootstrap.php';

class Elastica_Query_CustomScoreTest extends PHPUnit_Framework_TestCase
{
    public function testCustomScoreQuery()
    {
        $query = new Elastica_Query_MatchAll();

        $customScoreQuery = new Elastica_Query_CustomScore();
        $customScoreQuery->setQuery($query);
        $customScoreQuery->setScript("doc['hits'].value * (param1 + param2)");
        $customScoreQuery->addParams(array('param1' => 1123, 'param2' => 2001));

        $expected = array(
            'custom_score' => array(
                'query' => array(
                    'match_all' => new stdClass,
                ),
                'script' => "doc['hits'].value * (param1 + param2)",
                'params' => array(
                    'param1' => 1123,
                    'param2' => 2001,
                )
            )
        );

        $this->assertEquals($expected, $customScoreQuery->toArray());
    }

    public function testSetScript()
    {
        $string = '_score * 2.0';
        $lang = 'mvel';
        $params = array(
            'param1' => 'one',
            'param2' => 1,
        );
        $script = new Elastica_Script($string);
        $script->setLang('mvel');
        $script->setParams($params);

        $customScoreQuery = new Elastica_Query_CustomScore();
        $customScoreQuery->setScript($script);

        $expected = array(
            'custom_score' => array(
                'query' => array(
                    'match_all' => new stdClass,
                ),
                'script' => $string,
                'params' => $params,
                'lang' => $lang,
            )
        );

        $this->assertEquals($expected, $customScoreQuery->toArray());
    }

    public function testConstructor()
    {
        $string = '_score * 2.0';
        $customScoreQuery = new Elastica_Query_CustomScore($string);

        $expected = array(
            'custom_score' => array(
                'query' => array(
                    'match_all' => new stdClass,
                ),
                'script' => $string,
            )
        );

        $this->assertEquals($expected, $customScoreQuery->toArray());
    }
}
{'fraction_non_alphanumeric': 0.14509420112551993, 'fraction_numerical': 0.014680694886224614, 'mean_word_length': 1.7054930509596293, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 63, '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': '814379', 'n_tokens_mistral': 1185, 'n_tokens_neox': 1105, 'n_words': 199}