mirror of
https://github.com/Codappix/search_core.git
synced 2024-11-22 08:56:47 +01:00
Merge branch 'feature/add-display-name-to-facet' into feature/cleanup
Conflicts: Classes/Connection/Elasticsearch/FacetOption.php Classes/Connection/FacetOptionInterface.php
This commit is contained in:
commit
89065305c4
3 changed files with 81 additions and 0 deletions
|
@ -29,6 +29,11 @@ class FacetOption implements FacetOptionInterface
|
||||||
*/
|
*/
|
||||||
protected $name = '';
|
protected $name = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $displayName = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
|
@ -40,6 +45,7 @@ class FacetOption implements FacetOptionInterface
|
||||||
public function __construct(array $bucket)
|
public function __construct(array $bucket)
|
||||||
{
|
{
|
||||||
$this->name = $bucket['key'];
|
$this->name = $bucket['key'];
|
||||||
|
$this->displayName = isset($bucket['key_as_string']) ? $bucket['key_as_string'] : $this->getName();
|
||||||
$this->count = $bucket['doc_count'];
|
$this->count = $bucket['doc_count'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,6 +54,11 @@ class FacetOption implements FacetOptionInterface
|
||||||
return $this->name;
|
return $this->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getDisplayName() : string
|
||||||
|
{
|
||||||
|
return $this->displayName;
|
||||||
|
}
|
||||||
|
|
||||||
public function getCount() : int
|
public function getCount() : int
|
||||||
{
|
{
|
||||||
return $this->count;
|
return $this->count;
|
||||||
|
|
|
@ -31,6 +31,12 @@ interface FacetOptionInterface
|
||||||
*/
|
*/
|
||||||
public function getName() : string;
|
public function getName() : string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If a pre-rendered name is provided, this will be returned.
|
||||||
|
* Otherwise it's the same as getName().
|
||||||
|
*/
|
||||||
|
public function getDisplayName() : string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of found results for this option.
|
* Returns the number of found results for this option.
|
||||||
*/
|
*/
|
||||||
|
|
64
Tests/Unit/Connection/Elasticsearch/FacetOptionTest.php
Normal file
64
Tests/Unit/Connection/Elasticsearch/FacetOptionTest.php
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
<?php
|
||||||
|
namespace Codappix\SearchCore\Tests\Unit\Connection\Elasticsearch;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2018 Daniel Siepmann <coding@daniel-siepmann.de>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Codappix\SearchCore\Connection\Elasticsearch\FacetOption;
|
||||||
|
use Codappix\SearchCore\Tests\Unit\AbstractUnitTestCase;
|
||||||
|
|
||||||
|
class FacetOptionTest extends AbstractUnitTestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function displayNameIsReturnedAsExpected()
|
||||||
|
{
|
||||||
|
$bucket = [
|
||||||
|
'key' => 'Name',
|
||||||
|
'key_as_string' => 'DisplayName',
|
||||||
|
'doc_count' => 10,
|
||||||
|
];
|
||||||
|
$subject = new FacetOption($bucket);
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
$bucket['key_as_string'],
|
||||||
|
$subject->getDisplayName(),
|
||||||
|
'Display name was not returned as expected.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function displayNameIsReturnedAsExpectedIfNotProvided()
|
||||||
|
{
|
||||||
|
$bucket = [
|
||||||
|
'key' => 'Name',
|
||||||
|
'doc_count' => 10,
|
||||||
|
];
|
||||||
|
$subject = new FacetOption($bucket);
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
$bucket['key'],
|
||||||
|
$subject->getDisplayName(),
|
||||||
|
'Display name was not returned as expected.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue