Skip to content
Snippets Groups Projects
MatchQuery.php 1.24 KiB
Newer Older
ONGR Team's avatar
ONGR Team committed
<?php

/*
 * This file is part of the ONGR package.
 *
 * (c) NFQ Technologies UAB <info@nfq.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace ONGR\ElasticsearchBundle\DSL\Query;

use ONGR\ElasticsearchBundle\DSL\BuilderInterface;
use ONGR\ElasticsearchBundle\DSL\ParametersTrait;

/**
 * Elasticsearch match query class.
 */
class MatchQuery implements BuilderInterface
{
    use ParametersTrait;

    /**
     * @var string
     */
Mantas Jonušas's avatar
Mantas Jonušas committed
    private $field;
ONGR Team's avatar
ONGR Team committed

    /**
     * @var string
     */
Mantas Jonušas's avatar
Mantas Jonušas committed
    private $query;
ONGR Team's avatar
ONGR Team committed

    /**
     * @param string $field
Mantas Jonušas's avatar
Mantas Jonušas committed
     * @param string $query
ONGR Team's avatar
ONGR Team committed
     * @param array  $parameters
     */
Mantas Jonušas's avatar
Mantas Jonušas committed
    public function __construct($field, $query, array $parameters = [])
ONGR Team's avatar
ONGR Team committed
    {
        $this->field = $field;
Mantas Jonušas's avatar
Mantas Jonušas committed
        $this->query = $query;
ONGR Team's avatar
ONGR Team committed
        $this->setParameters($parameters);
    }

    /**
     * {@inheritdoc}
     */
    public function getType()
    {
        return 'match';
    }

    /**
     * {@inheritdoc}
     */
    public function toArray()
    {
        $query = [
            'query' => $this->query,
        ];

        $output = [
            $this->field => $this->processArray($query),
        ];

        return $output;
    }
}