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

added a basic integration test for spellcheck, highlighter and facets (#575)

* added a basic integration test for spellcheck, highlighter and facets
* added missing getSuggester() to select result
* fixed return type of getHighlighting() on a select result
* fixed return type of getFacetSet() on a select result
parent df55b388
...@@ -4,10 +4,12 @@ namespace Solarium\QueryType\Select\Result; ...@@ -4,10 +4,12 @@ namespace Solarium\QueryType\Select\Result;
use Solarium\Component\ComponentAwareQueryInterface; use Solarium\Component\ComponentAwareQueryInterface;
use Solarium\Component\Result\Debug\Result as DebugResult; use Solarium\Component\Result\Debug\Result as DebugResult;
use Solarium\Component\Result\Facet\Field;
use Solarium\Component\Result\Grouping\Result as GroupingResult; use Solarium\Component\Result\Grouping\Result as GroupingResult;
use Solarium\Component\Result\Highlighting\Result as HighlightingResult; use Solarium\Component\Result\Highlighting\Highlighting;
use Solarium\Component\Result\MoreLikeThis\Result as MoreLikeThisResult; use Solarium\Component\Result\MoreLikeThis\Result as MoreLikeThisResult;
use Solarium\Component\Result\Spellcheck\Result as SpellcheckResult; use Solarium\Component\Result\Spellcheck\Result as SpellcheckResult;
use Solarium\Component\Result\Suggester\Result as SuggesterResult;
use Solarium\Component\Result\Stats\Result as StatsResult; use Solarium\Component\Result\Stats\Result as StatsResult;
use Solarium\Core\Query\Result\QueryType as BaseResult; use Solarium\Core\Query\Result\QueryType as BaseResult;
...@@ -246,7 +248,7 @@ class Result extends BaseResult implements \IteratorAggregate, \Countable ...@@ -246,7 +248,7 @@ class Result extends BaseResult implements \IteratorAggregate, \Countable
* *
* This is a convenience method that maps presets to getComponent * This is a convenience method that maps presets to getComponent
* *
* @return HighlightingResult|null * @return Highlighting|null
*/ */
public function getHighlighting() public function getHighlighting()
{ {
...@@ -270,7 +272,7 @@ class Result extends BaseResult implements \IteratorAggregate, \Countable ...@@ -270,7 +272,7 @@ class Result extends BaseResult implements \IteratorAggregate, \Countable
* *
* This is a convenience method that maps presets to getComponent * This is a convenience method that maps presets to getComponent
* *
* @return FacetSet|null * @return Field[]|null
*/ */
public function getFacetSet() public function getFacetSet()
{ {
...@@ -289,6 +291,18 @@ class Result extends BaseResult implements \IteratorAggregate, \Countable ...@@ -289,6 +291,18 @@ class Result extends BaseResult implements \IteratorAggregate, \Countable
return $this->getComponent(ComponentAwareQueryInterface::COMPONENT_SPELLCHECK); return $this->getComponent(ComponentAwareQueryInterface::COMPONENT_SPELLCHECK);
} }
/**
* Get suggester component result.
*
* This is a convenience method that maps presets to getComponent
*
* @return SuggesterResult|null
*/
public function getSuggester()
{
return $this->getComponent(ComponentAwareQueryInterface::COMPONENT_SUGGESTER);
}
/** /**
* Get stats component result. * Get stats component result.
* *
......
...@@ -112,6 +112,72 @@ abstract class AbstractTechproductsTest extends TestCase ...@@ -112,6 +112,72 @@ abstract class AbstractTechproductsTest extends TestCase
$this->assertSame(10, $result->count()); $this->assertSame(10, $result->count());
} }
public function testFacetHighlightSpellcheckComponent()
{
$select = $this->client->createSelect();
// In the techproducts example, the request handler "select" doesn't neither contain a spellcheck component nor
// a highlighter or facets. But the "browse" request handler does.
$select->setHandler('browse');
// Search for misspelled "power cort".
$select->setQuery('power cort');
$spellcheck = $select->getSpellcheck();
// Some spellcheck dictionaries needs to build first, but not on every request!
$spellcheck->setBuild(true);
$result = $this->client->select($select);
$this->assertSame(0, $result->getNumFound());
$this->assertSame([
'power' => 'power',
'cort' => 'cord',
],
$result->getSpellcheck()->getCollations()[0]->getCorrections());
$words = [];
foreach ($result->getSpellcheck()->getSuggestions()[0]->getWords() as $suggestion) {
$words[] = $suggestion['word'];
}
$this->assertEquals([
'corp',
'cord',
'card',
], $words);
$select->setQuery('power cord');
// Activate highlighting.
$select->getHighlighting();
$facetSet = $select->getFacetSet();
$facetSet->createFacetField('stock')->setField('inStock');
$result = $this->client->select($select);
$this->assertSame(1, $result->getNumFound());
foreach ($result as $document) {
$this->assertSame('F8V7067-APL-KIT', $document->id);
}
$this->assertSame(
['car <b>power</b> adapter, white'],
$result->getHighlighting()->getResult('F8V7067-APL-KIT')->getField('features'));
$this->assertSame(
['Belkin Mobile <b>Power</b> <b>Cord</b> for iPod w&#x2F; Dock'],
$result->getHighlighting()->getResult('F8V7067-APL-KIT')->getField('name'));
$this->assertSame([
'features' => ['car <b>power</b> adapter, white'],
'name' => ['Belkin Mobile <b>Power</b> <b>Cord</b> for iPod w&#x2F; Dock'],
],
$result->getHighlighting()->getResult('F8V7067-APL-KIT')->getFields());
foreach ($result->getFacetSet() as $facetFieldName => $facetField) {
$this->assertSame('stock', $facetFieldName);
// The power cord is not in stock! In the techproducts example that is reflected by the string 'false'.
$this->assertSame(1, $facetField->getValues()['false']);
}
}
public function testSpatial() public function testSpatial()
{ {
$select = $this->client->createSelect(); $select = $this->client->createSelect();
......
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