<commit_before><?php

/*
 * This file is part of the Rollerworks Search Component package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Rollerworks\Component\Search;

/**
 * @author <NAME> <<EMAIL>>
 */
class SearchConditionBuilder
{
    /**
     * @var ValuesGroup
     */
    protected $valuesGroup;

    /**
     * @var SearchConditionBuilder
     */
    protected $parent;

    /**
     * Constructor.
     *
     * @param string                 $logical
     * @param SearchConditionBuilder $parent
     */
    public function __construct($logical = ValuesGroup::GROUP_LOGICAL_AND, SearchConditionBuilder $parent = null)
    {
        $this->valuesGroup = new ValuesGroup($logical);
        $this->parent = $parent;
    }

    /**
     * @param string $logical
     *
     * @return SearchConditionBuilder
     */
    public static function create($logical = ValuesGroup::GROUP_LOGICAL_AND)
    {
        return new self($logical);
    }

    /**
     * @param $logical
     *
     * @return SearchConditionBuilder
     */
    public function group($logical = ValuesGroup::GROUP_LOGICAL_AND)
    {
        $builder = new self($logical, $this);
        $this->valuesGroup->addGroup($builder->getGroup());

        return $builder;
    }

    /**
     * @param string $name
     *
     * @return ValuesBagBuilder
     */
    public function field($name)
    {
        $valuesBag = new ValuesBagBuilder($this);
        $this->valuesGroup->addField($name, $valuesBag);

        return $valuesBag;
    }

    /**
     * @return SearchConditionBuilder
     */
    public function end()
    {
        return null !== $this->parent ? $this->parent : $this;
    }

    /**
     * @return ValuesGroup
     */
    public function getGroup()
    {
        return $this->valuesGroup;
    }
}<commit_msg>change SearchConditionBuilder to accept a FieldSet and create a SearchCondition<commit_after><?php

/*
 * This file is part of the Rollerworks Search Component package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Rollerworks\Component\Search;

use Rollerworks\Component\Search\Exception\BadMethodCallException;

/**
 * @author <NAME> <<EMAIL>>
 */
class SearchConditionBuilder
{
    /**
     * @var ValuesGroup
     */
    protected $valuesGroup;

    /**
     * @var SearchConditionBuilder
     */
    protected $parent;

    /**
     * @var FieldSet
     */
    protected $fieldSet;

    /**
     * Constructor.
     *
     * @param string                 $logical
     * @param FieldSet               $fieldSet
     * @param SearchConditionBuilder $parent
     */
    public function __construct($logical = ValuesGroup::GROUP_LOGICAL_AND, FieldSet $fieldSet = null, SearchConditionBuilder $parent = null)
    {
        $this->valuesGroup = new ValuesGroup($logical);
        $this->parent = $parent;
        $this->fieldSet = $fieldSet;
    }

    /**
     * Creates a new SearchConditionBuilder.
     *
     * @param FieldSet $fieldSet
     * @param string   $logical
     *
     * @return SearchConditionBuilder
     */
    public static function create(FieldSet $fieldSet = null, $logical = ValuesGroup::GROUP_LOGICAL_AND)
    {
        return new self($logical, $fieldSet);
    }

    /**
     * @param $logical
     *
     * @return SearchConditionBuilder
     */
    public function group($logical = ValuesGroup::GROUP_LOGICAL_AND)
    {
        $builder = new self($logical, null, $this);
        $this->valuesGroup->addGroup($builder->getGroup());

        return $builder;
    }

    /**
     * @param string  $name
     * @param boolean $forceNew
     *
     * @return ValuesBagBuilder
     */
    public function field($name, $forceNew = false)
    {
        if (!$forceNew && $this->valuesGroup->hasField($name)) {
            $valuesBag = $this->valuesGroup->getField($name);
        } else {
            $valuesBag = new ValuesBagBuilder($this);
            $this->valuesGroup->addField($name, $valuesBag);
        }

        return $valuesBag;
    }

    /**
     * @return SearchConditionBuilder
     */
    public function end()
    {
        return null !== $this->parent ? $this->parent : $this;
    }

    /**
     * @return ValuesGroup
     */
    public function getGroup()
    {
        return $this->valuesGroup;
    }

    /**
     * @return SearchCondition
     *
     * @throws BadMethodCallException when there is no FieldSet configured.
     */
    public function getSearchCondition()
    {
        if ($this->parent) {
            return $this->parent->getSearchCondition();
        }

        if (null === $this->fieldSet) {
            throw new BadMethodCallException('Unable to create SearchCondition without FieldSet.');
        }

        return new SearchCondition($this->fieldSet, $this->valuesGroup);
    }

    /**
     * @return FieldSet
     */
    public function getFieldSet()
    {
        return $this->fieldSet;
    }
}
{'fraction_non_alphanumeric': 0.121875, 'fraction_numerical': 0.0, 'mean_word_length': 2.237041719342604, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 47, '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': '3748187', 'n_tokens_mistral': 1464, 'n_tokens_neox': 1427, 'n_words': 339}