Skip to content
Snippets Groups Projects
Commit a100480c authored by Mantas Jonušas's avatar Mantas Jonušas
Browse files

Added addQuery() method in DisMaxQuery

parent 0cfa9a76
No related branches found
No related tags found
No related merge requests found
...@@ -29,23 +29,27 @@ class DisMaxQuery implements BuilderInterface ...@@ -29,23 +29,27 @@ class DisMaxQuery implements BuilderInterface
/** /**
* Initializes Dis Max query. * Initializes Dis Max query.
* *
* @param BuilderInterface[] $queries * @param array $parameters
* @param array $parameters
*
* @throws \InvalidArgumentException
*/ */
public function __construct(array $queries = [], array $parameters = []) public function __construct(array $parameters = [])
{ {
foreach ($queries as $query) {
if ($query instanceof BuilderInterface) {
$this->queries[] = $query;
} else {
throw new \InvalidArgumentException('Arguments must be instance of BuilderInterface');
}
}
$this->setParameters($parameters); $this->setParameters($parameters);
} }
/**
* Add query.
*
* @param BuilderInterface $query
*
* @return $this
*/
public function addQuery(BuilderInterface $query)
{
$this->queries[] = $query;
return $this;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
...@@ -59,6 +63,7 @@ class DisMaxQuery implements BuilderInterface ...@@ -59,6 +63,7 @@ class DisMaxQuery implements BuilderInterface
*/ */
public function toArray() public function toArray()
{ {
$query = [];
foreach ($this->queries as $type) { foreach ($this->queries as $type) {
$query['queries'][] = [$type->getType() => $type->toArray()]; $query['queries'][] = [$type->getType() => $type->toArray()];
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment