Commit d88ed3fb authored by Markus Kalkbrenner's avatar Markus Kalkbrenner Committed by GitHub

4.x suggester (#535)

Cleaned up suggester query and added missing parameters
parent 5702044e
......@@ -60,6 +60,8 @@ class Query extends BaseQuery
'resultclass' => 'Solarium\QueryType\Suggester\Result\Result',
'termclass' => 'Solarium\QueryType\Suggester\Result\Term',
'omitheader' => true,
'build' => false,
'reload' => false,
);
/**
......@@ -165,48 +167,70 @@ class Query extends BaseQuery
}
/**
* Set onlyMorePopular option.
* Set cfq option.
*
* Only return suggestions that result in more hits for the query than the existing query
* A Context Filter Query used to filter suggestions based on the context field, if supported by the suggester.
*
* @param boolean $onlyMorePopular
* @param string $cfq
*
* @return self Provides fluent interface
*/
public function setOnlyMorePopular($onlyMorePopular)
public function setContextFilterQuery($cfq)
{
return $this->setOption('onlymorepopular', $onlyMorePopular);
return $this->setOption('cfq', $cfq);
}
/**
* Get onlyMorePopular option.
* Get cfq option.
*
* @return string|null
*/
public function getContextFilterQuery()
{
return $this->getOption('cfq');
}
/**
* Set build option.
*
* @param boolean $build
*
* @return self Provides fluent interface
*/
public function setBuild($build)
{
return $this->setOption('build', $build);
}
/**
* Get build option.
*
* @return boolean|null
*/
public function getOnlyMorePopular()
public function getBuild()
{
return $this->getOption('onlymorepopular');
return $this->getOption('build');
}
/**
* Set collate option.
* Set reload option.
*
* @param boolean $collate
* @param boolean $build
*
* @return self Provides fluent interface
*/
public function setCollate($collate)
public function setReload($reload)
{
return $this->setOption('collate', $collate);
return $this->setOption('reload', $reload);
}
/**
* Get collate option.
* Get reload option.
*
* @return boolean|null
*/
public function getCollate()
public function getReload()
{
return $this->getOption('collate');
return $this->getOption('reload');
}
}
......@@ -60,9 +60,12 @@ class RequestBuilder extends BaseRequestBuilder
{
$request = parent::build($query);
$request->addParam('suggest', 'true');
$request->addParam('suggest.q', $query->getQuery());
$request->addParam('suggest.dictionary', $query->getDictionary());
$request->addParam('suggest.q', $query->getQuery());
$request->addParam('suggest.count', $query->getCount());
$request->addParam('suggest.cfq', $query->getContextFilterQuery());
$request->addParam('suggest.build', $query->getBuild());
$request->addParam('suggest.reload', $query->getReload());
return $request;
}
......
......@@ -94,25 +94,46 @@ class QueryTest extends \PHPUnit_Framework_TestCase
);
}
public function testSetAndGetOnlyMorePopular()
public function testSetAndGetContextFilterQuery()
{
$value = false;
$this->query->setOnlyMorePopular($value);
$value = 'context filter query';
$this->query->setContextFilterQuery($value);
$this->assertEquals(
$value,
$this->query->getOnlyMorePopular()
$this->query->getContextFilterQuery()
);
}
public function testSetAndGetCollate()
public function testSetAndBuild()
{
$value = false;
$this->query->setCollate($value);
$this->assertEquals(
false,
$this->query->getBuild()
);
$value = true;
$this->query->setBuild($value);
$this->assertEquals(
$value,
$this->query->getBuild()
);
}
public function testSetAndReload()
{
$this->assertEquals(
false,
$this->query->getReload()
);
$value = true;
$this->query->setReload($value);
$this->assertEquals(
$value,
$this->query->getCollate()
$this->query->getReload()
);
}
}
......@@ -55,18 +55,23 @@ class RequestBuilderTest extends \PHPUnit_Framework_TestCase
public function testBuildParams()
{
$this->query->setCount(13);
$this->query->setDictionary('suggest');
$this->query->setQuery('ap ip');
$this->query->setCount(13);
$this->query->setContextFilterQuery('foo bar');
$this->query->setBuild('true');
$request = $this->builder->build($this->query);
$this->assertEquals(
array(
'suggest' => 'true',
'suggest.q' => 'ap ip',
'suggest.dictionary' => 'suggest',
'suggest.q' => 'ap ip',
'suggest.count' => 13,
'suggest.cfq' => 'foo bar',
'suggest.build' => 'true',
'suggest.reload' => 'false',
'wt' => 'json',
'json.nl' => 'flat',
'omitHeader' => 'true',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment