Commit d97b5855 authored by Bas de Nooijer's avatar Bas de Nooijer

Merge branch 'develop' into feature/nextgen

Conflicts:
	library/Solarium/QueryType/Select/Query/Component/Facet/Query.php
	library/Solarium/QueryType/Select/Result/Spellcheck/Result.php
	tests/Solarium/Tests/QueryType/Select/Result/Spellcheck/SpellcheckTest.php
parents e47db28d 97b94e14
......@@ -40,13 +40,16 @@ foreach($spellcheckResult as $suggestion) {
echo '<hr/>';
}
$collation = $spellcheckResult->getCollation();
echo '<h1>Collation</h1>';
echo 'Query: '.$collation->getQuery().'<br/>';
echo 'Hits: '.$collation->getHits().'<br/>';
$collations = $spellcheckResult->getCollations();
echo '<h1>Collations</h1>';
foreach($collations as $collation) {
echo 'Query: '.$collation->getQuery().'<br/>';
echo 'Hits: '.$collation->getHits().'<br/>';
echo '<hr/>';
}
echo 'Corrections:<br/>';
foreach($collation->getCorrections() as $input => $correction) {
echo $input . ' => ' . $correction .'<br/>';
}
htmlFooter();
\ No newline at end of file
htmlFooter();
......@@ -173,4 +173,37 @@ abstract class Query extends Configurable implements QueryInterface
return $this->params;
}
/**
* Set responsewriter option
*
* @param string $value
* @return self Provides fluent interface
*/
public function setResponseWriter($value)
{
return $this->setOption('responsewriter', $value);
}
/**
* Get responsewriter option
*
* Defaults to json for BC and full query support.
*
* If you can fully trust the Solr responses (phps has a security risk from untrusted sources) you might consider
* setting the responsewriter to 'phps' (serialized php). This can give a performance advantage,
* especially with big resultsets. Phps response parsing has not been extensively tested for all querytypes, so it's
* still experimental. It works for standard updates and select queries, but be sure to test your queries.
*
* @return string
*/
public function getResponseWriter()
{
$responseWriter = $this->getOption('responsewriter');
if ($responseWriter === null ) {
$responseWriter = 'json';
}
return $responseWriter;
}
}
......@@ -59,7 +59,7 @@ abstract class RequestBuilder implements RequestBuilderInterface
$request->setHandler($query->getHandler());
$request->addParam('omitHeader', $query->getOmitHeader());
$request->addParams($query->getParams());
$request->addParam('wt', 'json');
$request->addParam('wt', $query->getResponseWriter());
return $request;
}
......
......@@ -42,6 +42,7 @@ use Solarium\Core\Client\Response;
use Solarium\Exception\HttpException;
use Solarium\Core\Query\Query;
use Solarium\Exception\UnexpectedValueException;
use Solarium\Exception\RuntimeException;
/**
* Query result
......@@ -134,13 +135,24 @@ class Result implements ResultInterface
*
* Includes a lazy loading mechanism: JSON body data is decoded on first use and then saved for reuse.
*
* @throws UnexpectedValueException
* @throws UnexpectedValueException, RuntimeException
* @return array
*/
public function getData()
{
if (null == $this->data) {
$this->data = json_decode($this->response->getBody(), true);
switch ($this->query->getResponseWriter()) {
case 'phps':
$this->data = unserialize($this->response->getBody());
break;
case 'json':
$this->data = json_decode($this->response->getBody(), true);
break;
default:
throw new RuntimeException('Responseparser cannot handle ' . $this->query->getResponseWriter());
}
if (null === $this->data) {
throw new UnexpectedValueException(
'Solr JSON response could not be decoded'
......
......@@ -94,7 +94,7 @@ class Result implements \IteratorAggregate, \Countable
} else {
if ($key === null) {
$key = $nrOfCollations - 1; // for backwards compatibility
return reset($this->collations);
}
return $this->collations[$key];
......
......@@ -88,6 +88,21 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase
3 => 'ultrasharp'
),
),
8 => 'collation',
9 => array (
0 => 'collationQuery',
1 => 'dell ultrasharp new',
2 => 'hits',
3 => 0,
4 => 'misspellingsAndCorrections',
5 => array (
0 => 'delll',
1 => 'dell',
2 => 'ultrashar',
3 => 'ultrasharp'
),
),
)
)
);
......@@ -98,6 +113,9 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(false, $result->getCorrectlySpelled());
$this->assertEquals('dell', $suggestions[0]->getWord());
$this->assertEquals('dell ultrasharp', $result->getCollation()->getQuery());
$collations = $result->getCollations();
$this->assertEquals('dell ultrasharp', $collations[0]->getQuery());
$this->assertEquals('dell ultrasharp new', $collations[1]->getQuery());
}
public function testParse()
......@@ -132,6 +150,8 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase
5 => false,
6 => 'collation',
7 => 'dell ultrasharp',
8 => 'collation',
9 => 'dell ultrasharp new',
)
)
);
......@@ -142,6 +162,10 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(false, $result->getCorrectlySpelled());
$this->assertEquals('dell', $suggestions[0]->getWord());
$this->assertEquals('dell ultrasharp', $result->getCollation()->getQuery());
$collations = $result->getCollations();
$this->assertEquals('dell ultrasharp', $collations[0]->getQuery());
$this->assertEquals('dell ultrasharp new', $collations[1]->getQuery());
}
public function testParseNoData()
......
......@@ -40,7 +40,7 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase
*/
protected $result;
protected $suggestions, $collation, $correctlySpelled;
protected $suggestions, $collations, $correctlySpelled;
public function setUp()
{
......@@ -48,7 +48,11 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase
'key1' => 'content1',
'key2' => 'content2',
);
$this->collations = array('dummy1', 'dummy2');
$this->collations = array(
'dummy1',
'dummy2'
);
$this->correctlySpelled = false;
$this->result = new Result($this->suggestions, $this->collations, $this->correctlySpelled);
......@@ -56,7 +60,7 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase
public function testGetCollation()
{
$this->assertEquals($this->collations[1], $this->result->getCollation());
$this->assertEquals(reset($this->collations), $this->result->getCollation());
}
public function testGetCollationWithoutData()
......
......@@ -33,6 +33,7 @@ namespace Solarium\Tests\QueryType\Update;
use Solarium\Core\Client\Response;
use Solarium\QueryType\Update\Result;
use Solarium\QueryType\Update\ResponseParser;
use Solarium\QueryType\Select\Query\Query as SelectQuery;
class ResponseParserTest extends \PHPUnit_Framework_TestCase
{
......@@ -42,7 +43,7 @@ class ResponseParserTest extends \PHPUnit_Framework_TestCase
$data = '{"responseHeader" : {"status":1,"QTime":15}}';
$response = new Response($data, array('HTTP 1.1 200 OK'));
$result = new Result(null,null,$response);
$result = new Result(null, new SelectQuery, $response);
$parser = new ResponseParser;
$parsed = $parser->parse($result);
......
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