<?php
/**
 * Implementation of "sltr" query from ltr-query plugin
 *
 * @link https://github.com/o19s/elasticsearch-learning-to-rank
 *
 * @license GPL-2.0-or-later
 */

namespace CirrusSearch\Elastica;

use Elastica\Query\AbstractQuery;

class LtrQuery extends AbstractQuery {
	/**
	 * @param string $model The stored model to use
	 * @param string[] $params map of string -> string containing templating
	 *  parameters for ltr features.
	 */
	public function __construct( $model, array $params ) {
		$this->setModel( $model )
			->setLtrParams( $params );
	}

	/**
	 * @return string
	 */
	protected function _getBaseName() {
		return "sltr";
	}

	/**
	 * The stored model to use.
	 *
	 * @param string $model
	 * @return self
	 */
	public function setModel( $model ) {
		$this->setParam( 'model', $model );

		return $this;
	}

	/**
	 * The name of the feature store to find the model in.
	 *
	 * @param string $store
	 * @return self
	 */
	public function setStore( $store ) {
		$this->setParam( 'store', $store );

		return $this;
	}

	/**
	 * Add a parameter used for templated features
	 *
	 * @param string $key
	 * @param string $value
	 * @return self
	 */
	public function addLtrParam( $key, $value ) {
		$this->_params['params'][$key] = $value;

		return $this;
	}

	/**
	 * Set all parameters used for templated features.
	 *
	 * @param string[] $params map of string -> string containing templating
	 *  parameters for ltr features.
	 * @return self
	 */
	public function setLtrParams( array $params ) {
		$this->setParam( 'params', $params );

		return $this;
	}
}
