Commit 981af911 authored by Bas de Nooijer's avatar Bas de Nooijer

Improved return types. Fixed spellcheck parsing for multiple collations.

parent 43d502ca
......@@ -88,7 +88,7 @@ class Curl extends Configurable implements AdapterInterface
*
* @param Request $request
* @param Endpoint $endpoint
* @return array
* @return Response
*/
protected function getData($request, $endpoint)
{
......
......@@ -347,7 +347,7 @@ class Client extends Configurable
/**
* Get all endpoints
*
* @return array
* @return Endpoint[]
*/
public function getEndpoints()
{
......@@ -626,7 +626,7 @@ class Client extends Configurable
/**
* Get all registered plugins
*
* @return array
* @return PluginInterface[]
*/
public function getPlugins()
{
......
......@@ -54,9 +54,24 @@ abstract class ResponseParser
*/
public function convertToKeyValueArray($data)
{
// key counter to convert values to arrays when keys are re-used
$keys = array();
$result = array();
for ($i = 0; $i < count($data); $i += 2) {
$result[$data[$i]] = $data[$i+1];
$key = $data[$i];
$value = $data[$i+1];
if (array_key_exists($key, $keys)) {
if($keys[$key] == 1) {
$result[$key] = array($result[$key]);
}
$result[$key][] = $value;
$keys[$key]++;
} else {
$keys[$key] = 1;
$result[$key] = $value;
}
}
return $result;
......
......@@ -41,6 +41,7 @@ use Solarium\Client;
use Solarium\Core\Plugin\Plugin;
use Solarium\QueryType\Update\Result as UpdateResult;
use Solarium\QueryType\Update\Query\Query as UpdateQuery;
use Solarium\QueryType\Select\Result\DocumentInterface;
use Solarium\QueryType\Select\Result\Document as ReadOnlyDocument;
use Solarium\Plugin\BufferedAdd\Event\Events;
use Solarium\Plugin\BufferedAdd\Event\PreFlush as PreFlushEvent;
......@@ -76,7 +77,7 @@ class BufferedAdd extends Plugin
/**
* Buffered documents
*
* @var array
* @var DocumentInterface[]
*/
protected $buffer = array();
......@@ -132,7 +133,7 @@ class BufferedAdd extends Plugin
/**
* Add a document
*
* @param ReadOnlyDocument $document
* @param DocumentInterface $document
* @return self Provides fluent interface
*/
public function addDocument($document)
......@@ -165,7 +166,7 @@ class BufferedAdd extends Plugin
*
* Any previously flushed documents will not be included!
*
* @return array
* @return DocumentInterface[]
*/
public function getDocuments()
{
......
......@@ -39,6 +39,7 @@
namespace Solarium\Plugin\BufferedAdd\Event;
use Symfony\Component\EventDispatcher\Event;
use Solarium\QueryType\Update\Result;
use Solarium\QueryType\Select\Result\DocumentInterface;
/**
* PostCommit event, see Events for details
......@@ -64,7 +65,7 @@ class PostCommit extends Event
/**
* Get the result for this event
*
* @return array
* @return DocumentInterface[]
*/
public function getResult()
{
......
......@@ -39,6 +39,7 @@
namespace Solarium\Plugin\BufferedAdd\Event;
use Symfony\Component\EventDispatcher\Event;
use Solarium\QueryType\Update\Result;
use Solarium\QueryType\Select\Result\DocumentInterface;
/**
* PostFlush event, see Events for details
......@@ -64,7 +65,7 @@ class PostFlush extends Event
/**
* Get the result for this event
*
* @return array
* @return DocumentInterface[]
*/
public function getResult()
{
......
......@@ -38,6 +38,7 @@
*/
namespace Solarium\Plugin\BufferedAdd\Event;
use Symfony\Component\EventDispatcher\Event;
use Solarium\QueryType\Select\Result\DocumentInterface;
/**
* PreCommit event, see Events for details
......@@ -87,7 +88,7 @@ class PreCommit extends Event
/**
* Get the buffer for this event
*
* @return array
* @return DocumentInterface[]
*/
public function getBuffer()
{
......
......@@ -38,6 +38,7 @@
*/
namespace Solarium\Plugin\BufferedAdd\Event;
use Symfony\Component\EventDispatcher\Event;
use Solarium\QueryType\Select\Result\DocumentInterface;
/**
* PreFlush event, see Events for details
......@@ -77,7 +78,7 @@ class PreFlush extends Event
/**
* Get the buffer for this event
*
* @return array
* @return DocumentInterface[]
*/
public function getBuffer()
{
......
......@@ -194,7 +194,7 @@ class CustomizeRequest extends Plugin
/**
* Get all Customizations
*
* @return array
* @return Customization[]
*/
public function getCustomizations()
{
......
......@@ -264,7 +264,7 @@ class Loadbalancer extends Plugin
/**
* Get the endpoints in the loadbalancing pool
*
* @return array
* @return Endpoint[]
*/
public function getEndpoints()
{
......
......@@ -42,6 +42,7 @@ use Solarium\Core\Client\Endpoint;
use Solarium\Exception\HttpException;
use Solarium\Core\Client\Client;
use Solarium\Core\Query\Query;
use Solarium\Core\Query\Result;
use Solarium\Plugin\ParallelExecution\Event\Events;
use Solarium\Plugin\ParallelExecution\Event\ExecuteStart as ExecuteStartEvent;
use Solarium\Plugin\ParallelExecution\Event\ExecuteEnd as ExecuteEndEvent;
......@@ -113,7 +114,7 @@ class ParallelExecution extends Plugin
/**
* Get queries (and coupled client instances)
*
* @return array
* @return Query[]
*/
public function getQueries()
{
......@@ -137,7 +138,7 @@ class ParallelExecution extends Plugin
/**
* Execute queries parallel
*
* @return array
* @return Result[]
*/
public function execute()
{
......
......@@ -40,6 +40,7 @@ namespace Solarium\QueryType\Analysis\Query;
use Solarium\Core\Client\Client;
use Solarium\QueryType\Analysis\ResponseParser\Document as ResponseParser;
use Solarium\QueryType\Analysis\RequestBuilder\Document as RequestBuilder;
use Solarium\QueryType\Select\Result\DocumentInterface;
/**
* Analysis document query
......@@ -111,7 +112,7 @@ class Document extends Query
/**
* Add multiple documents
*
* @param array $documents
* @param DocumentInterface[] $documents
* @return self fluent interface
*/
public function addDocuments($documents)
......@@ -124,7 +125,7 @@ class Document extends Query
/**
* Get all documents
*
* @return array
* @return DocumentInterface[]
*/
public function getDocuments()
{
......
......@@ -38,6 +38,7 @@
*/
namespace Solarium\QueryType\Analysis\ResponseParser;
use Solarium\QueryType\Analysis\Result as AnalysisResult;
use Solarium\QueryType\Analysis\Result\ResultList;
/**
* Parse document analysis response data
......@@ -50,14 +51,14 @@ class Document extends Field
*
* @param Result $result
* @param array $data
* @return array
* @return ResultList[]
*/
protected function parseAnalysis($result, $data)
{
$documents = array();
foreach ($data as $documentKey => $documentData) {
$fields = $this->parseTypes($result, $documentData);
$documents[] = new AnalysisResult\ResultList($documentKey, $fields);
$documents[] = new ResultList($documentKey, $fields);
}
return $documents;
......
......@@ -39,6 +39,9 @@
namespace Solarium\QueryType\Analysis\ResponseParser;
use Solarium\Core\Query\Result\Result;
use Solarium\QueryType\Analysis\Result as AnalysisResult;
use Solarium\QueryType\Analysis\Result\ResultList;
use Solarium\QueryType\Analysis\Result\Item;
use Solarium\QueryType\Analysis\Result\Types;
use Solarium\Core\Query\ResponseParser as ResponseParserAbstract;
use Solarium\Core\Query\ResponseParserInterface as ResponseParserInterface;
......@@ -72,7 +75,7 @@ class Field extends ResponseParserAbstract implements ResponseParserInterface
*
* @param Result $result
* @param array $data
* @return array
* @return Types[]
*/
protected function parseAnalysis($result, $data)
{
......@@ -90,7 +93,7 @@ class Field extends ResponseParserAbstract implements ResponseParserInterface
*
* @param Result $result
* @param array $typeData
* @return array
* @return Types[]
*/
protected function parseTypes($result, $typeData)
{
......@@ -116,7 +119,7 @@ class Field extends ResponseParserAbstract implements ResponseParserInterface
foreach ($typeData as $class => $analysis) {
if (is_string($analysis)) {
$item = new AnalysisResult\Item(
$item = new Item(
array(
'text' => $analysis,
'start' => null,
......@@ -127,23 +130,23 @@ class Field extends ResponseParserAbstract implements ResponseParserInterface
)
);
$classes[] = new AnalysisResult\ResultList($class, array($item));
$classes[] = new ResultList($class, array($item));
} else {
$items = array();
foreach ($analysis as $itemData) {
$items[] = new AnalysisResult\Item($itemData);
$items[] = new Item($itemData);
}
$classes[] = new AnalysisResult\ResultList($class, $items);
$classes[] = new ResultList($class, $items);
}
}
$types[] = new AnalysisResult\ResultList($typeKey, $classes);
$types[] = new ResultList($typeKey, $classes);
}
$results[] = new AnalysisResult\Types($fieldKey, $types);
$results[] = new Types($fieldKey, $types);
}
return $results;
......
......@@ -38,6 +38,7 @@
*/
namespace Solarium\QueryType\Analysis\Result;
use Solarium\Core\Query\Result\QueryType as BaseResult;
use Solarium\QueryType\Analysis\Result\ResultList;
/**
* Analysis document query result
......@@ -101,7 +102,7 @@ class Document extends BaseResult implements \IteratorAggregate, \Countable
/**
* Get all documents
*
* @return array
* @return ResultList[]
*/
public function getDocuments()
{
......
......@@ -187,7 +187,7 @@ class MultiQuery extends Facet
/**
* Get all facetqueries
*
* @return array
* @return Query[]
*/
public function getQueries()
{
......
......@@ -42,6 +42,7 @@ use Solarium\QueryType\Select\RequestBuilder\Component\FacetSet as RequestBuilde
use Solarium\QueryType\Select\ResponseParser\Component\FacetSet as ResponseParser;
use Solarium\Exception\InvalidArgumentException;
use Solarium\Exception\OutOfBoundsException;
use Solarium\QueryType\Select\Query\Component\Facet\Facet;
/**
* MoreLikeThis component
......@@ -344,7 +345,7 @@ class FacetSet extends Component
/**
* Get all facets
*
* @return array
* @return Facet[]
*/
public function getFacets()
{
......
......@@ -43,6 +43,7 @@ use Solarium\QueryType\Select\RequestBuilder\RequestBuilder;
use Solarium\QueryType\Select\ResponseParser\ResponseParser;
use Solarium\Exception\InvalidArgumentException;
use Solarium\Exception\OutOfBoundsException;
use Solarium\QueryType\Select\Query\Component\Component;
/**
* Select Query
......@@ -706,7 +707,7 @@ class Query extends BaseQuery
/**
* Get all filterqueries
*
* @return array
* @return FilterQuery[]
*/
public function getFilterQueries()
{
......@@ -786,7 +787,7 @@ class Query extends BaseQuery
/**
* Get all registered components
*
* @return array
* @return Component[]
*/
public function getComponents()
{
......
......@@ -74,14 +74,19 @@ class Spellcheck extends ResponseParserAbstract
$correctlySpelled = null;
$collations = array();
foreach ($spellcheckResults as $key => $value) {
switch ($key) {
case 'correctlySpelled':
$correctlySpelled = $value;
break;
case 'collation':
if(!array_key_exists('collation', $value)){
foreach($value as $collationValue) {
$collations[] = $this->parseCollation($query, $collationValue);
}
}else{
$collations[] = $this->parseCollation($query, $value);
}
break;
default:
$suggestions[] = $this->parseSuggestion($key, $value);
......
......@@ -37,6 +37,7 @@
* @namespace
*/
namespace Solarium\QueryType\Select\Result\Highlighting;
use Solarium\QueryType\Select\Result\Highlighting\Result;
/**
* Select component highlighting result
......@@ -80,7 +81,7 @@ class Highlighting implements \IteratorAggregate, \Countable
/**
* Get all results
*
* @return array
* @return Result[]
*/
public function getResults()
{
......
......@@ -37,6 +37,7 @@
* @namespace
*/
namespace Solarium\QueryType\Select\Result\MoreLikeThis;
use Solarium\QueryType\Select\Result\MoreLikeThis\Result;
/**
* Select component morelikethis result
......@@ -80,7 +81,7 @@ class MoreLikeThis implements \IteratorAggregate, \Countable
/**
* Get all results
*
* @return array
* @return Result[]
*/
public function getResults()
{
......
......@@ -37,6 +37,7 @@
* @namespace
*/
namespace Solarium\QueryType\Select\Result\MoreLikeThis;
use Solarium\QueryType\Select\Result\DocumentInterface;
/**
* Select component morelikethis result item
......@@ -108,7 +109,7 @@ class Result implements \IteratorAggregate, \Countable
/**
* Get all documents
*
* @return array
* @return DocumentInterface[]
*/
public function getDocuments()
{
......
......@@ -39,6 +39,7 @@
namespace Solarium\QueryType\Select\Result;
use Solarium\QueryType\Select\Query\Query as SelectQuery;
use Solarium\Core\Query\Result\QueryType as BaseResult;
use Solarium\QueryType\Select\Result\DocumentInterface;
/**
* Select query result
......@@ -148,7 +149,7 @@ class Result extends BaseResult implements \IteratorAggregate, \Countable
/**
* Get all documents
*
* @return array
* @return DocumentInterface[]
*/
public function getDocuments()
{
......
......@@ -37,6 +37,8 @@
* @namespace
*/
namespace Solarium\QueryType\Select\Result\Spellcheck;
use Solarium\QueryType\Select\Result\Spellcheck\Collation;
use Solarium\QueryType\Select\Result\Spellcheck\Suggestion;
/**
* Select component spellcheck result
......@@ -104,7 +106,7 @@ class Result implements \IteratorAggregate, \Countable
/**
* Get all collations
*
* @return array
* @return Collation[]
*/
public function getCollations()
{
......@@ -141,7 +143,7 @@ class Result implements \IteratorAggregate, \Countable
/**
* Get all suggestions
*
* @return array
* @return Suggestion[]
*/
public function getSuggestions()
{
......
......@@ -37,6 +37,7 @@
* @namespace
*/
namespace Solarium\QueryType\Select\Result\Stats;
use Solarium\QueryType\Select\Result\Stats\Result;
/**
* Select component stats result
......@@ -80,7 +81,7 @@ class Stats implements \IteratorAggregate, \Countable
/**
* Get all results
*
* @return array
* @return Result[]
*/
public function getResults()
{
......
......@@ -115,7 +115,7 @@ class Add extends Command
/**
* Get all documents
*
* @return array
* @return DocumentInterface[]
*/
public function getDocuments()
{
......
......@@ -43,6 +43,12 @@ use Solarium\QueryType\Update\RequestBuilder;
use Solarium\QueryType\Update\ResponseParser;
use Solarium\Exception\RuntimeException;
use Solarium\Exception\InvalidArgumentException;
use Solarium\QueryType\Update\Query\Command\Command;
use Solarium\QueryType\Update\Query\Command\Add as AddCommand;
use Solarium\QueryType\Update\Query\Command\Commit as CommitCommand;
use Solarium\QueryType\Update\Query\Command\Delete as DeleteCommand;
use Solarium\QueryType\Update\Query\Command\Optimize as OptimizeCommand;
use Solarium\QueryType\Update\Query\Command\Rollback as RollbackCommand;
/**
* Update query
......@@ -178,7 +184,7 @@ class Query extends BaseQuery
* @throws InvalidArgumentException
* @param string $type
* @param mixed $options
* @return Command\Command
* @return Command
*/
public function createCommand($type, $options = null)
{
......@@ -196,7 +202,7 @@ class Query extends BaseQuery
/**
* Get all commands for this update query
*
* @return array
* @return Command[]
*/
public function getCommands()
{
......@@ -260,7 +266,7 @@ class Query extends BaseQuery
*/
public function addRollback()
{
return $this->add(null, new Command\Rollback);
return $this->add(null, new RollbackCommand);
}
/**
......@@ -274,7 +280,7 @@ class Query extends BaseQuery
*/
public function addDeleteQuery($query)
{
$delete = new Command\Delete;
$delete = new DeleteCommand;
$delete->addQuery($query);
return $this->add(null, $delete);
......@@ -291,7 +297,7 @@ class Query extends BaseQuery
*/
public function addDeleteQueries($queries)
{
$delete = new Command\Delete;
$delete = new DeleteCommand;
$delete->addQueries($queries);
return $this->add(null, $delete);
......@@ -308,7 +314,7 @@ class Query extends BaseQuery
*/
public function addDeleteById($id)
{
$delete = new Command\Delete;
$delete = new DeleteCommand;
$delete->addId($id);
return $this->add(null, $delete);
......@@ -325,7 +331,7 @@ class Query extends BaseQuery
*/
public function addDeleteByIds($ids)
{
$delete = new Command\Delete;
$delete = new DeleteCommand;
$delete->addIds($ids);
return $this->add(null, $delete);
......@@ -362,7 +368,7 @@ class Query extends BaseQuery
public function addDocuments($documents, $overwrite = null,
$commitWithin = null)
{
$add = new Command\Add;
$add = new AddCommand;
if (null !== $overwrite) {
$add->setOverwrite($overwrite);
......@@ -391,7 +397,7 @@ class Query extends BaseQuery
public function addCommit($softCommit = null, $waitSearcher = null,
$expungeDeletes = null)
{
$commit = new Command\Commit();
$commit = new CommitCommand();
if (null !== $softCommit) {
$commit->setSoftCommit($softCommit);
......@@ -422,7 +428,7 @@ class Query extends BaseQuery
public function addOptimize($softCommit = null, $waitSearcher = null,
$maxSegments = null)
{
$optimize = new Command\Optimize();
$optimize = new OptimizeCommand();
if (null !== $softCommit) {
$optimize->setSoftCommit($softCommit);
......
......@@ -31,14 +31,16 @@
namespace Solarium\Tests\QueryType\Select\ResponseParser\Component;
use Solarium\QueryType\Select\ResponseParser\Component\Spellcheck as Parser;
use Solarium\QueryType\Select\Query\Query;
class SpellcheckTest extends \PHPUnit_Framework_TestCase
{
protected $parser;
protected $parser, $query;
public function setUp()
{
$this->query = new Query();
$this->parser = new Parser();
}
......@@ -107,7 +109,7 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase
)
);
$result = $this->parser->parse(null, null, $data);
$result = $this->parser->parse($this->query, null, $data);
$suggestions = $result->getSuggestions();
$this->assertEquals(false, $result->getCorrectlySpelled());
......@@ -156,7 +158,7 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase
)
);
$result = $this->parser->parse(null, null, $data);
$result = $this->parser->parse($this->query, null, $data);
$suggestions = $result->getSuggestions();
$this->assertEquals(false, $result->getCorrectlySpelled());
......@@ -170,7 +172,7 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase
public function testParseNoData()
{
$result = $this->parser->parse(null, null, array());
$result = $this->parser->parse($this->query, null, array());
$this->assertEquals(null, $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